12-31-2008 12:08 PM
Hello all,
My program is 35 VI level tall and quite wide. While executing the program I pop up a progress bar windows that shows the current status, along with this screen comes a cancel button. When a user cancels task, is there anyway to force the program to stop executing immediately without quitting the program? I have a lot of for and while loops, is there any quick and easy way to end all task immediately/break all the loops? thanks
Solved! Go to Solution.
12-31-2008 12:51 PM - edited 12-31-2008 12:55 PM
lavalava wrote:Hello all,
My program is 35 VI level tall and quite wide. While executing the program I pop up a progress bar windows that shows the current status, along with this screen comes a cancel button. When a user cancels task, is there anyway to force the program to stop executing immediately without quitting the program? I have a lot of for and while loops, is there any quick and easy way to end all task immediately/break all the loops? thanks
Quoting Ed Dickens from this thread "using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.".
So to be a purest always urging proper LabVIEW code regardless of the work to realize such I have to answer "NO, no easy way." You will have to find all of the loops your code can be busy in and modify them to monitor a stop flag, check the state of a button on the GUi etc. This is where a good design helps avoid the situation I think I hear you describing.
But if I switch hats to "hacker mode" I would suggest you look a the "stop"* and "quit LabVIEW"* functions available on the "application Control" palette. But I don't recomnd these functions and would prefer you implmement a global stop flag.
Ben
* Depending on the application and its hardware along with what is happening when a VI is aborted, you shoule EXPECT to have to manually kill the LV process occationally, and from time to time expect to re-boot to get it working again, so PLEASE don't use the either of those methods to stop an application that is running.
12-31-2008 02:33 PM - edited 12-31-2008 02:34 PM
lavalava wrote:When a user cancels task, is there anyway to force the program to stop executing immediately without quitting the program?
Listen to Ben, of course. 😉
Some additional notes:
12-31-2008 11:43 PM - edited 12-31-2008 11:44 PM
You could programmatically abort if you want:

This basically aborts if the cancel button's value is true.
01-01-2009 01:58 AM
Hi lavalava,
lavalava wrote:...is there anyway to force the program to stop executing immediately without quitting the program?
If you're asking: "Is there an easy way to terminate execution of code without stopping LabVIEW"
Then identical to the "Stop" function, why not use the "Abort Execution" button in the tool-bar?
If you're asking: "Is there an easy way to stop loops and other processes, without stopping the top-level VI"
Then no - unless each and every loop has been designed to check some external "abort" condition.
Instead of calling a "Stop" or "Exit" function, pressing "Cancel" could set a global "Abort" boolean and loops that check the global would stop.
An occurrance can serve the same function - loops call Wait On Occurrance with Ignore Previous = False, Timeout=0 and checking for Timeout=False. Cancel=> Generate Occurrance.
A boolean Notifier works similarly.
Queues and Notifiers, when destroyed, can signal "Abort" to loops that wait on them.
Cheers!
01-02-2009 10:49 AM
tbd wrote:
If you're asking: "Is there an easy way to stop loops and other processes, without stopping the top-level VI"
Then no - unless each and every loop has been designed to check some external "abort" condition.
Instead of calling a "Stop" or "Exit" function, pressing "Cancel" could set a global "Abort" boolean and loops that check the global would stop.
Yes, that's what I'm referring to. Aborting is very obvious but how can I do it so that it kills all lower level loops without affecting the top one. Obviously the top level VI loop needs to be in tact otherwise the entire prog would shut down and my users would lose their saved works.
I think I'll go with the first poster's suggestion about using a global variable and I'll replace all of my for loops with while loop. Not a bad idea, pretty neat as a matter of fact. Thanks for all the suggestion fellas. Happy new year. Cheers!