11-29-2008 01:16 PM
Hi all,
I want to display a wait panel with an animation in it when my app is processing data, using the animation control. The problem is that the animation freezes because all the resources are in the data processing (when it's no data processing, the animation works correctly).
I tried to create a thread for running the wait panel on it, but it continues freezing because there's a loop waiting for when data processing is finished. I created another thread for that loop, and now the animation works, but only if there's events over the waiting panel (moving the mouse over it or something).
I know this is not very efficient. Maybe someone knows an easy way to do this.
Thank you!!
My code is this:
int Calculate (...)
{
ShowWaitPanel();
//DATA PROCESSING...
HideWaitPanel();
}
void ShowWaitPanel(void)
{
waitPanelActive=1;
CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE,WaitThreadFunction,
NULL,&waitThreadFunctionId);
}
void HideWaitPanel(void)
{
waitPanelActive=0;
CmtWaitForThreadPoolFunctionCompletion (DEFAULT_THREAD_POOL_HANDLE,
waitThreadFunctionId,OPT_TP_PROCESS_EVENTS_WHILE_WAITING);
CmtReleaseThreadPoolFunctionID (DEFAULT_THREAD_POOL_HANDLE, waitThreadFunctionId);
}
static int CVICALLBACK WaitThreadFunction (void *functionData)
{
waitPanelHandle = LoadPanel (0, "SpectrumAnalyzer.uir", WAITPANEL);
DisplayPanel (waitPanelHandle);
AnimateCtrl_ConvertFromPictRing (waitPanelHandle, WAITPANEL_PICTURERING);
AnimateCtrl_SetAttribute (waitPanelHandle, WAITPANEL_PICTURERING, ATTR_ANIMATE_ENABLED, 1);
AnimateCtrl_SetAttribute (waitPanelHandle, WAITPANEL_PICTURERING, ATTR_ANIMATE_FRAME_INTERVAL, 0.1);
AnimateCtrl_SetAttribute (waitPanelHandle, WAITPANEL_PICTURERING, ATTR_ANIMATE_STOP_ON_LAST_FRAME, 0);
CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE,CheckWaitPanelFlagThread,NULL,&checkWaitFlagThreadId);
CmtWaitForThreadPoolFunctionCompletion (DEFAULT_THREAD_POOL_HANDLE,checkWaitFlagThreadId,
OPT_TP_PROCESS_EVENTS_WHILE_WAITING);
CmtReleaseThreadPoolFunctionID (DEFAULT_THREAD_POOL_HANDLE, checkWaitFlagThreadId);
DiscardPanel (waitPanelHandle);
return 0;
}
static int CVICALLBACK CheckWaitPanelFlagThread (void *functionData)
{
while(waitPanelActive)
{
}Solved! Go to Solution.
12-04-2008 04:55 PM
12-04-2008 05:51 PM
You need to process events. The second scheduled thread function is not necessary. Try this:
static int CVICALLBACK WaitThreadFunction (void *functionData)
{
waitPanelHandle = LoadPanel (0, "SpectrumAnalyzer.uir", WAITPANEL);
DisplayPanel (waitPanelHandle);
AnimateCtrl_ConvertFromPictRing (waitPanelHandle, WAITPANEL_PICTURERING);
AnimateCtrl_SetAttribute (waitPanelHandle, WAITPANEL_PICTURERING, ATTR_ANIMATE_ENABLED, 1);
AnimateCtrl_SetAttribute (waitPanelHandle, WAITPANEL_PICTURERING, ATTR_ANIMATE_FRAME_INTERVAL, 0.1);
AnimateCtrl_SetAttribute (waitPanelHandle, WAITPANEL_PICTURERING, ATTR_ANIMATE_STOP_ON_LAST_FRAME, 0);
while(waitPanelActive)
{
ProcessSystemEvents();
}DiscardPanel (waitPanelHandle);
Mert A.
National Instruments
12-04-2008 06:34 PM
It works perfectly.
Thank you very much!!
Eduardo - Spain