LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Question about closing an applciation

I have created an application and I had a question about how to control closing the application.  In the application you can close it by pressing the 'x' button on the top right hand of the window or by choosing the file menu and pressing 'exit'.  Now i need to do some stuff before the application closes, which in fact determines whether the application will indeed close or the action will be discarded.
 
I have attached a simple vi and runtime menu to demonstrate my case
 
To discard the 'x' button i have placed and event loop with the 'Panel close?' case, however i could not get this to work with the 'Exit' option in the file menu.  The 'Exit' can be discarded if i place an 'Application Instance Close?' event case but then i would have to repeat eveything i did in the 'Panel close?' case here again which i prefer not to do since it doesn't look that clean.
 
I tried changing the 'Exit' in the file menu to a 'user item' instead of an 'application item' and close the application with a case structure, as you can see in the attached vi, but it didn't help.  It would close the panel and not enter the 'Panel close?' event case
 
Again my basic point is that i am trying to control exiting the application, instead of exiting it right away i want to do a bunch of stuff and then decide whether the applicaiton can be exited or more work is required.  As you can see the vi or application works for now but i was wondering whether there was a better way i might have missed
 
I hope i have been clear enough.
 
Thanks
 
Reza
 
 
PS i had to change the extension of the menu from rtm to txt to attach the file, please change it back when you have downloaded it
Download All
0 Kudos
Message 1 of 5
(2,677 Views)
Put the event structure in a state-machine with three states (init, main, quit).

In the Init case place all initialisation code and go to the main state.
In the main case put the event structure and stay in the main state until either the "panel close?" event (should be discarded) or the "Menu selection? (app):Exit" event occur (should both be discarded), but should transition to the quit state.
In the quit state do housekeeping before exitting the while loop around the state-machine.

Hope it helps.
Regards,
André (CLA, CLED)
0 Kudos
Message 2 of 5
(2,660 Views)
yeah thanks, that did help
0 Kudos
Message 3 of 5
(2,654 Views)
Reza,

Here is a slightly different approach.  I hid a button on my front panel called exit.  In the value change event handler for that button is where I had my exit logic.  In the "Panel Close?" event handler and the menu handler for exit I would do a val(signal) change via property node on that button to activate my exit logic.  That kept all the logic in one place and I could call my exit from anywhere.

Note: In this example the Discard? is always set to true in the "Panel Close?"
Greg Cole
“It is not the ship so much as the skillful sailing that ensures the prosperous voyage.”
Message 4 of 5
(2,642 Views)
The state-machine approach seems the cleanest way for me.
One more thing. If you plan to build application you should probably also read this and especially this about the "professional" way of exiting the application.
LV 2011, Win7
0 Kudos
Message 5 of 5
(2,628 Views)