Thanks Luis,
I found another way, where I use CmtSchedule Advance function and register a
callback which gets called when my thread is finished. So when user clicks a
button on main panel, I start my thread, and exit the button's callback
function (rather than just sitting there with CmtWait function). This way I
can keep processing UIR events on main panel.
vishi
"Luis Gomes" wrote in message
news:5065000000050000007EC10000-1031838699000@exchange.ni.com...
> Vishi,
>
> The reason you are seeing this is because there is a difference
> between CVI UI events and operating system events. The
> OPT_TP_PROCESS_EVENTS_WHILE_WAITING option allows you to process
> operating system events, but not UI events. This is why your UI is
> blocking.
>
> I realize that this distinction is not very obvious, and therefore in
> the next version of CVI we are changing the behavior of
> OPT_TP_PROCESS_EVENTS_WHILE_WAITING to also process UI events.
>
> In the meanwhile, whenever the wait for a thread to complete is
> non-negligible, you should wait in the following manner:
>
> threadCompleted = FALSE;
> CmtScheduleThreadPoolFunction(DEFAULT_THREAD_POOL_ HANDLE,
> RunTestThreadFunction, NULL,
> &functionId);
> // Wait for test to complete
> while (!threadCompleted)
> ProcessSystemEvents();
> CmtWaitForThreadPoolFunctionCompletion(DEFAULT_THR EAD_POOL_HANDLE,
> functionId, OPT_TP_PROCESS_EVENTS_WHILE_WAITING);
>
>
> int CVICALLBACK RunTestThreadFunction(void* pFunctionData)
> {
> Wait(10.0);
> threadCompleted = TRUE;
> return 0;
> }
>
> The call to ProcessSystemEvents() will process both types of events.
>
> Notice that I still left the CmtWaitForThreadPoolFunctionCompletion
> call. The reason for that is that there could be a small amount of
> time after the thread function has set the flag but before the thread
> has really exited. The additional wait will ensure that the thread has
> really completed. In this case, the wait time will be short enough
> that it should not have any effect on your UI.
>
> Luis Gomes
> NI