Skip to main content
CreateThreadpoolWait function

Creates a new wait object.


PTP_WAIT WINAPI CreateThreadpoolWait(
  _In_        PTP_WAIT_CALLBACK    pfnwa,
  _Inout_opt_ PVOID                pv,
  _In_opt_    PTP_CALLBACK_ENVIRON pcbe


pfnwa [in]

The callback function to call when the wait completes or times out. For details, see WaitCallback.

pv [in, out, optional]

Optional application-defined data to pass to the callback function.

pcbe [in, optional]

A TP_CALLBACK_ENVIRON structure that defines the environment in which to execute the callback. The InitializeThreadpoolEnvironment function returns this structure.

If this parameter is NULL, the callback executes in the default callback environment. For more information, see InitializeThreadpoolEnvironment.

Return value

If the function succeeds, it returns a TP_WAIT structure that defines the wait object. Applications do not modify the members of this structure.

If the function fails, it returns NULL. To retrieve extended error information, call GetLastError.


To set the wait object, call the SetThreadpoolWait function.

The work item and all functions it calls must be thread-pool safe. Therefore, you cannot call an asynchronous call that requires a persistent thread, such as the RegNotifyChangeKeyValue function, from the default callback environment. Instead, set the thread pool maximum equal to the thread pool minimum using the SetThreadpoolThreadMaximum and SetThreadpoolThreadMinimum functions, or create your own thread using the CreateThread function.

Windows 8:   RegNotifyChangeKeyValue can be called from a work item by setting the REG_NOTIFY_THREAD_AGNOSTIC flag.

To compile an application that uses this function, define _WIN32_WINNT as 0x0600 or higher.


For an example, see Using the Thread Pool Functions.


Minimum supported client

Windows Vista [desktop apps | UWP apps]

Minimum supported server

Windows Server 2008 [desktop apps | UWP apps]


WinBase.h on Windows Vista, Windows 7, Windows Server 2008 and Windows Server 2008 R2 (include Windows.h);
Threadpoolapiset.h on Windows 8 and Windows Server 2012





See also

Thread Pools