Hi Marlise,
I suggest you to put the part of code that consume time proccess in a
seperate thread and all the rest user interface mechanism handling in the
main process thread, check out the following example:
#include
#include "Panel.h"
static int panel;
static BOOL CancelRequested=FALSE;
void Thread_SomeTask()
{
while(CancelRequested==FALSE)
{
// Place your task here
Sleep(500);
InsertListItem(panel,PANEL_LISTBOX, -1,"I am still busy",0);
// Other things to do
}
ExitThread(1);
}
int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR
lpszCmdLine, int nCmdShow)
{
BOOL result;
DWORD ThrdID,ExitCode;
HANDLE ThrdHandle;
// Create a separate thread for some task that consume long time
ThrdHandle=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)Thread_SomeTask,NULL,
0,&ThrdID);
// Load, Display and Run the UserInterface loop
panel=LoadPanel(0,"Panel.uir",PANEL);
DisplayPanel(panel);
RunUserInterface();
DiscardPanel(panel);
// Make sure that the task thread was exited normaly
do
{
result=GetExitCodeThread(ThrdHandle,&ExitCode);
}
while(result == TRUE && ExitCode == STILL_ACTIVE);
CloseHandle(ThrdHandle);
return 0;
}
int CVICALLBACK MainPanel_Exit (int panel, int control, int event,void
*callbackData, int eventData1, int eventData2)
{
switch(event)
{
case EVENT_COMMIT:
CancelRequested=TRUE; // This will make the thread to stop
its loop and exit
QuitUserInterface(0);
break;
}
return 0;
}
Marlise wrote in message
news:38ce91cf@newsgroups.ni.com...
>
> I have a CVI that takes up to 30 minutes to complete one of the tasks. I
> want to make it possible for the user to quit during the download if they
> want to but I am having trouble doing that from within the download loop.
> I have tried GetUserEvent, ProcessSystemEvents, and several other
functions
> inside my loop and can't seem to get them to do what I am asking. Is
there
> a way to exit out of the loop if someone clicks Quit on the user interface
> while a seperate function is already running?
>
> Thanks.