Stop a While Loop with a Long Wait Time in LabVIEW

Updated Oct 18, 2023

Reported In

Software

  • LabVIEW

Issue Details

  • How do I stop a While Loop with a Wait (ms) timer before it finishes its cycle?
  • I have a very long Wait (ms) time delay in my cycle and when I click the stop button, it takes too long to stop.
  • How can I abort a While Loop in the middle of execution while it is waiting?
  • How can I interrupt a Wait (ms) time function?

Solution

You can't stop a Wait (ms) while it is executing. Nevertheless, there are some options available for you to be able to stop a While Loop without waiting a very high amount of time.

 

When you use the Wait (ms) timing VI inside a While Loop, you allow the processor to execute other tasks in its queue, before coming back to check on your While Loop again. Therefore, it's always a good practice to keep your Wait (ms) numeric input in a low number. If you want your code to execute in a slower pace, and still be able to stop the cycle in a responsive way, try using the Elapsed Time Express VI, or create your own timer, as shown in the Community Example: FGV Timer.

 

The Elapsed Time Express VI indicates the amount of time that has elapsed since the specified start time. Use the Elapsed time (seconds) input to specify how much time must elapse before the Time has Elapsed Boolean is set to TRUE. (The default is 1.000). Review an example of code using this function here:

 

Additional Information

For better performance, consider using a Producer/Consumer architecture, QMH, or Dynamic Events. These architectures allow the processor to offload when the application is in Idle state, while using more efficient mechanisms to stop the execution when needed.