From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Function calls

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.
0 Kudos
Message 1 of 3
(2,973 Views)
Hi Marlise,
Use a global variable as a terminate flag.
Set the flag in the callback for your quit button.
Test the flag in your loop, and terminate the loop
if the flag is set.
Don't forget to call ProcessSystemEvents() inside
your loop.
Regards,
Reed.

//----------------------------------------------------------
Reed Blake
Beta Technology
Industrial and Scientific Computing


Marlise wrote in message <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.
0 Kudos
Message 2 of 3
(2,973 Views)
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.
0 Kudos
Message 3 of 3
(2,973 Views)