PostDeferredCallToThreadAndWait

int PostDeferredCallToThreadAndWait (DeferredCallbackPtr deferredFunction, void *callbackData, unsigned long targetThreadID, int timeout);

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.

To obtain the id of a 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 long 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.

To obtain the id of a thread, call the Utility Library function CmtGetCurrentThreadId.
timeout integer 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 integer 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.