Stop a While Loop Before My Wait Time Elapses in LabVIEW

Updated Aug 24, 2023

Reported In

Software

  • LabVIEW Base
  • LabVIEW Professional
  • LabVIEW Full

Issue Details

I have a While loop with a long Wait (ms) time or Wait Until Next ms Multiple function. My Stop button takes too long to stop my loop. How can I program my Stop button to end a while loop immediately?

Solution

The Wait (ms) and Wait Until Next ms Multiple functions allow your processor to perform other pending tasks by sending the loop to an idle mode until the time has elapsed. When using large numbers as inputs to these VIs, the result can be a long wait time that will cause any change to be read after the time runs out and the cycle executes again.

 

A simple workaround can be adding an Elapsed Time express VI with a Case Structure to let the cycle run faster without affecting the timed functionality of your code. This solution will poll changes more often and will allow you to stop the loop without having to wait the complete wait time.
 

Additional Information

For larger applications, consider using a Producer-Consumer design pattern, as well as Custom Events to get better performance. Navigate to Help»Find Examples…»Optimizing Applications»Synchronizing Tasks»Simple Queue.vi in LabVIEW to find a working example of a Producer-Consumer architecture.