PostDeferredCallToThreadAndWait
int PostDeferredCallToThreadAndWait (DeferredCallbackPtr deferredFunction, void *callbackData, unsigned int targetThreadId, int timeout_ms);
Purpose
Call this function when you want to execute a callback function in a particular thread and you want to wait until that callback function finishes executing before continuing execution in the current thread.
You pass a callback function pointer, callback data, a thread ID, and a timeout to PostDeferredCallToThreadAndWait. If the thread ID you pass is the same as the current thread's ID, PostDeferredCallToThreadAndWait calls the callback function directly. If the thread ID you pass is different than the current thread's id, PostDeferredCallToThreadAndWait calls PostDeferredCallToThread and then sleeps until your callback finishes executing or until the timeout expires.
![]() |
Note To obtain the ID of the thread, call the Utility Library function CmtGetCurrentThreadId. |
Parameters
Input | ||||
Name | Type | Description | ||
deferredFunction | DeferredCallbackPtr | Pass a pointer to the function that you want to execute in a particular thread. The function you pass in this parameter must have the following prototype: void CVICALLBACK FunctionName (void *callbackData); |
||
callbackData | void * | This parameter specifies a user–defined value that will be passed to the deferred callback function when it is called. | ||
targetThreadId | unsigned int | Pass the thread ID of the thread that you want to execute the Deferred Function. The thread that you post the call to must process messages by calling RunUserInterface, GetUserEvent, or ProcessSystemEvents.
|
||
timeout_ms | int | Pass the maximum amount of time, in milliseconds, that PostDeferredCallToThreadAndWait should wait for the callback function to be executed. Pass POST_CALL_WAIT_TIMEOUT_INFINITE to indicate that PostDeferredCallToThreadAndWait should not return until the callback function finishes executing. |
Return Value
Name | Type | Description |
status | int | The status code that the function returns. 0 indicates success. A negative value indicates an error. This function may return a Programmer's Toolbox or UI Library error–code. Call GetGeneralErrorString to obtain a text description of the error. |
Additional Information
Library: Programmer's Toolbox
Include file: toolbox\toolbox.h
LabWindows/CVI compatibility: LabWindows/CVI 5.5 and later