07-23-2013 04:27 PM - edited 07-23-2013 04:30 PM
Hi all,
I'm having the same issue as the one described here, that is to say that when the user clicks the X in the right top corner of a LV executable file, there is sill the icon in the taskbar:
Therefore, I'm trying to implement the following code (posted in the link above) in my program:
In the program, I want the user to be able to click on the X and quit the program at anytime he/she wants, and not only at the end. Therefore, I am not sure how to implement that or if it is even possible.
Does anybody has an idea?
Thanks
07-23-2013 04:50 PM
With the diagram you have when the user clicks X at anytime it will quit the VI , not sure how you have integrated with the top level VI but this snippet will quit anytime X is pressed.
If this is not the case please elaborate on what behavior are you seeing?
07-23-2013 04:58 PM
Thank you for looking at my case Ivrat.
If I underderstand correctly, the diagram will close the window only if the program is in the loop of the diagram at that time, right? I mean if the program is doing something completely different (like displaying data or save a file) at the other side of the program, nothing will happen.
If I add this piece of code to my program (at the end of it basically), when I click on the X at any time while the program is running, nothing at all happens. Should I post a VI file to make it clear?
07-23-2013 08:58 PM
Yes, please post the VI.
You should never have several event structures, and if using only 1 your solution should work (although it's unnecessary, just wire the True to the stop loop). If you're in another event at the time, as a Save file-event, it's be queued up and processed afterwards.
/Y
07-24-2013 02:44 AM
Hello,
This is some code I use a lot and I think it does the same as you need?
In this case I catch the panel close event in order to handle some stuff first (like saving final settings to a file, disconnect from services and such) and only when that is done I actually close the vi myself.
I made a small example code for it. I catch the panel close event and discard it. Then I do everything I need to do and the vi will normally enter the stopped state (white run arrow). Now I do a check to see if it is running in development mode or not (typically runtime). If it is running in development mode this is where I stop so it is possible to do some work on the diagram.
If it is running on a runtime system I will close the panel using a property node and all is gone.
07-24-2013 02:24 PM
Thank you all for your answers.
My labview program is actually pretty big. I can make it simpler by removing/disabeling some parts, but the main idea is the program is made of a sequence. In the fourth step of the sequence, there is a gigantic while loop with the main core of the program. This loop includes many for and while loops. For now, I have put the FP handling in the last step of the top-level sequence. Therefore, when the program is in the gigantic while loop (or any of the sub-loops), clicking the X won't close the front panel until reaching the condition of the loop, right?
I actually have not posted the VI because while working on it, I realized that maybe I'm not thinking correctly the architecture of the program. Here is the situation:
- When the exe starts, the user has the choice between 2 buttons or to click on the X.
- If button #1 is clicked, the program executes an action and the user should be able to stop this action when he/she wants to come back to the initial state of the program
- If button #2 is clicked, the program executes an action and come back to the initial step of the program.
- If the X is cliked, the program quits. I would like this action to be work at any time while the program is running.
My first thought was to use the case structure in a while loop. It seems it is not the best choice from what you guys say.
Then I considered the event structure in a while loop. Seems a good idea, but when the program is running in the routine triggered by the button #1, if the user click the X, the program won't quit, right?
Please anybody correct me if I'm wrong because I'm not sure to fully understand how the event structures are working.
Thanks all.
07-24-2013 02:30 PM
You want to handle all UI events in a separate loop with the event structure. You can then send commands and status down to your other loop(s) using queues or notifiers. So with a notifier, you could tell your button 1 routine to quit.
07-25-2013 11:42 AM
As a starting point you can take a look at Queued Message Handler template (browse from LabVIEW Launch window >>Create Project). Here is the image of default template with the properties added.See if this helps.
07-25-2013 01:32 PM
@crossrulz wrote:
You want to handle all UI events in a separate loop with the event structure. You can then send commands and status down to your other loop(s) using queues or notifiers. So with a notifier, you could tell your button 1 routine to quit.
We also created a simple library for system events. We use this so that any code that is using the event structure can register with our system events and receive an Exit event which is generated by the UI or other section of code that is initiating the shutdown.