LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Halting loops with a button press

Solved!
Go to solution

I have an infinite loop getting and displaying data. How can I halt the loop with a button or keypress?

0 Kudos
Message 1 of 4
(3,256 Views)
Solution
Accepted by topic author tugofwar

Periodically perform a ProcessSystemEvents() call inside your loop. In a STOP button callback, set a flag to tell your loop to stop.

 

unsigned int stop = 0;

 

while (!stop) {

 

  getmeasured data

  display data

  ProcessSytemEvents()

  Sleep (250);   // to be polite:  it's rude to spinlock, since you'll hog the CPU and other threads can get starved

 

}

 

then, in the callback for a STOP button

 

// STOP button Callback routine

 

stop = 1;

 

 

 

Message 2 of 4
(3,244 Views)

Works. Thanks.

0 Kudos
Message 3 of 4
(3,220 Views)

You're welcome.

0 Kudos
Message 4 of 4
(3,206 Views)