From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to invoke only one click event if I clicked twice (event not finished)

Solved!
Go to solution

I use the template user interface. I then put a loop(simple index indicator) with stop button, inside the button event. If I click the button, the loop starts. Then I click the button one more time. I have to click the stop button twice to stop the loop. How can I make it not to queue my click?

0 Kudos
Message 1 of 6
(3,766 Views)

Some example code would help because I'm not completely sure of what you are doing but you can configure a maximum number of events for each event case which would mean that you could not queue up a second click event while you are still handling the first.

Matt J | National Instruments | CLA
0 Kudos
Message 2 of 6
(3,755 Views)

ask.png

 

I limit the maximum instance to 1. If I click the "command 1" twice, I have to click twice the "stop button" to stop the loop. Is it a bug? I am using labview 2015.

0 Kudos
Message 3 of 6
(3,751 Views)

It is a bug in the implementation of your code.  You do not want a long running while loop inside of the event case.

 

It is not a bug in LabVIEW.  It is queueing up only one event.  You hit the button, the event case starts executing pretty quickly and removes that event from the queue.  Now it needs to wait for you to hit stop to kill the while loop inside.  If you hit Button 1 again, it queues up that event and you now have 1 in the queue again.  So when you finally hit stop, it ends the first execution of the event.  The newly queued up one now runs, and you have to hit stop in order to stop that.

 

A producer/consumer architecture with events is a better architecture for this.  You could also get rid of the while loop, move the desired code into the timeout case.  Use a shift registers to change the timeout from -1 to 0.  Have an Stop button event that sets the timeout value back to -1.

0 Kudos
Message 4 of 6
(3,745 Views)

Thanks for your reply. I am wondering.... why labview cannot make the click/event instance removed after the things in the event is done......

0 Kudos
Message 5 of 6
(3,738 Views)
Solution
Accepted by tomsze

Because that is not the way it was designed.  The intention is to limit the number of events that are held in the queue, and discard the older events in case it overruns that limit.

 

How can you discard the oldest event if you have already begun executing it?  Technically, the first thing that happens when the event case runs is that it removes the event from the queue so that it can begin operating on it.

0 Kudos
Message 6 of 6
(3,734 Views)