LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to: Close Application Properly

Solved!
Go to solution

Hi all,

 

I could not find a recent (LV 2009) thread on this subject.

 

I have an application which consists of two main VIs.  The first VI (which the user never sees) calls the UI VI.

 

I have had trouble when the user wants to exit the UI VI.  If I allow them to press the cross (X) in the corner of the Window then the UI VI closes and leaves the caller VI still running.  To get around this I only allow them to push an Exit button on the UI front panel.  This invokes the Quit LabVIEW VI which shuts down both the caller and the UI.  This is not very elegant and there is a short flash of the caller VI when I do it this way.

 

I know there is some sort of App Event which I can use.  I want the user to be able to push the Window cross (X) in the corner and for this to close all running VIs.

 

Any examples you could provide would be greatly appreciated.

 

Battler. 

 

0 Kudos
Message 1 of 42
(7,421 Views)
Use the Panel Close? event.  It is under "This VI" in the event editor for the event structure.  Wire a True to the Discard? terminal to discard the panel close event.  Inside the event do whatever you need to do to exit the program like you are doing with your Exit button.  It may even be as simples as calling the Exit button's event by wiring a True to its Value(signalling) property node.  Or if you have a state machine, going to your exit/cleanup state and ending your program's overall while loop.  You may need to do a Panel.Close on the VI as one of the last steps of your program.
Message Edited by Ravens Fan on 04-01-2010 10:17 PM
Message 2 of 42
(7,406 Views)
That will close the UI front panel, but how do I also close the calling VI?
0 Kudos
Message 3 of 42
(7,396 Views)

How are you closing it now with the Exit button?

 

 

You could also do a close front panel on a reference to the calling VI.

 

0 Kudos
Message 4 of 42
(7,391 Views)

Using the Quit LabVIEW VI.

 

The calling VI doesn't have an Event Structure.

0 Kudos
Message 5 of 42
(7,386 Views)

Can you look at this thread:

 

http://forums.ni.com/ni/board/message?board.id=170&message.id=63179&query.id=1792880#M63179

 

"Closing by running the quit labview function results in a flash on the screen as the VI(s) stop and show their toolbar for a split second prior to closing. Not very elegant. So for built applications the best way to close is to do it by closing all the windows, then the application will quit nicely (off course, make sure you do all other exit operations."

0 Kudos
Message 6 of 42
(7,383 Views)

battler. wrote:

Using the Quit LabVIEW VI.

 

The calling VI doesn't have an Event Structure.


You said that Quit LabVIEW was working for you now using your exit button.

 

I never said anything about the calling VI needing an event structure.

 

The called VI has the event structure to capture the panel close event, discard it, and do what you do now to close both VI's.  If it is Quit LabVIEW and that works for you now, great.

 

Otherwise do something like this.

 

 

I'm not going to guarantee this will work precisely.  There may be details you'll have to work out based on your exact application.  Without seeing your exact application, I can't tell if there is anything special or extra you might have to do.  Why do you have a first VI that the user never sees?  What is the purpose of it?

Message Edited by Ravens Fan on 04-02-2010 12:12 AM
Message 7 of 42
(7,379 Views)

The problem (as stated by that thread I pointed to): "Closing by running the quit labview function results in a flash on the screen."

 

The VI the user never sees calls two VIs: 1. with a splash panel showing program details. 2. Calls the main UI VI subject to some error checking.

0 Kudos
Message 8 of 42
(7,363 Views)
....and that is why you should call the Front Panel:Close Method prior to calling the LabVIEW quit. LabVIEW quit is not meant to close the VI's for you. It's like a safety break for nonstandard situation like when your app is running and somebody kills it from the taskbar or so on. It is not meant to close your application in a clean way instead of you. To do that you have to handle clean quit yourself. What I usually do is that I have state for each independent (queued)state machine where I close the queue references, make sure other stuff is tidy and then I stop the while loop. When all the while loops are stopped the dataflow continues to Front Panel:Close Method and then LabVIEW quit(only in case of executable). Read more about using the quit function here
Message Edited by ceties on 04-02-2010 01:59 AM
LV 2011, Win7
Message 9 of 42
(7,357 Views)
What happens if the user clicks on the cross (X) in the corner of the UI VI (called by hidden VI)?  How can I handle this?  Is it covered by an Event?
0 Kudos
Message 10 of 42
(7,332 Views)