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?
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.
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.
Collaborate with other users in our discussion forums
A valid service agreement may be required, and support options vary by country.