LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with Breaking out of Loop using ProcessSystemEvents

Hello,

I'm having trouble with ProcessSystemEvents and still can't get this to work.

I have a batch file which takes about one minute to run. I'd like to have an infinite loop (right now set up as a for loop) and run the batch files until a user presses the STOP button. So the process starts, the DOS window comes up and my batch file starts. I maddly try click on STOP, but cannot get out of the loop. I never get the stop button pushed.

stoptheloop is a global variable. The panel this is happening from is a popup type, if that matters.

Any help or suggestions would be appreciated.

int CVICALLBACK BEGINLOOP (int panel, int control, int event,
void *callbackData, int eventDa
ta1, int eventData2)
{
int i;
switch (event)
{
case EVENT_COMMIT:
stoptheloop = 0;
for (i=1; i < 10; i++)
{
system("extvsimtb_switch6port.bat");
ProcessSystemEvents();
if (stoptheloop == 1) break;
DebugPrintf("stoptheloop = %d\n",stoptheloop);
}
break;
}
return 0;
}

int CVICALLBACK STOPLOOP (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
stoptheloop = 1;
break;
}
return 0;
}
0 Kudos
Message 1 of 3
(3,033 Views)
As stated in the System () function help, this function transfers control to the program executed and waits until this one has finished before returnig, ignoring mouse and keyboard events.

Much better is to use LaunchExecutable () in the Utility library, that returns immediately. To check if the launched program has ended, you can call ExecutableHasTerminated () in the same loop in which you are looking at stoptheloop variable.

The only problem I see is: how can you manage to stop the DOS batch processing in case the user presses the stop button?

Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 3
(3,033 Views)
Thanks for the answer. It works nicely (with LaunchExecutableEx). I just wait for the DOS batch processing to finish. I just needed a way to break out of the loop which calls the DOS batch processing.
0 Kudos
Message 3 of 3
(3,033 Views)