Controlling the Exit of Built Applications

Posted on Sunday 9 July 2006

If you’ve ever built stand-alone executable applications (written in LabVIEW, of course), then you probably know that there are special issues that do you have to deal with in built applications that are not quite as important when you are only running your application inside the LabVIEW development environment. One often overlooked issue is how an application exits and controlling that process.

One might assume (wrongly) that in stand-alone applications the only way that the application will exit is as a result of an action by the end user (captured as a user interface event) such as pressing the Stop button Stop Button, pressing the Close Window button Close Window Button, or by selecting a menu option. However, it is not uncommon for your application to exit as a result of the operating system requesting that your application exit. For example, the following are some very likely scenarios:

  • The user selects End Task from Windows Task Manager.
  • The user selects Quit from the Mac OS X Finder (or selects Quit from the right-click menu of your application’s icon in the dock)
  • The operating system is shutting down (either as a result of a user request Windows Shut Down Button, or otherwise), which causes the operating system to send your application a signal to exit.

When LabVIEW receives this exit signal from the operating system, it is equivalent to calling the Quit LabVIEW function, shown below.

Quit LabVIEW ConPane

According to the LabVIEW help documentation, the Quit LabVIEW function stops all executing VIs (in the same way as pressing the Abort Execution button on a VI’s toolbar) and then exits LabVIEW.


As you probably know, using the Abort Execution button is not a graceful way of exiting a running application. Just like you wouldn�t want your car to come to a stop by running it into a brick wall, you certainly do not want your application to exit by pressing the abort button. To exit your car driving experience, you slowly apply the brakes, downshift, find a nice place to park, come to a complete stop, and then turn off the key, get out, and then lock the door. You want to exit your application is exactly the same manor.

The good news is that we can receive notification of the fact that LabVIEW wants to exit by simply capturing (and discarding) the Application Exit? event in an Event Structure (see figure below), and then exiting programmatically.

Application Exit Event

The LabVIEW help documentation says that the Application Exit event is “generated when the user tries to exit LabVIEW”. But it actually applies to all of the scenarios (such as the exit messages sent from the operating system) mentioned previously.

Make sure that you register for the Application Exit? event and discard it by setting the Discard? filter data to TRUE.


The question mark at the end of the Application Exit? event means that it is a Filter Event, having a Filter Data node (with “Discard?” filter data, which should be set to TRUE, in this case). The Application Exit event (without a question mark at the end) is a Notify Event, which does not have the Filter Data node and therefore does not have the ability to discard the event.

You must discard the Application Exit? event and then programmatically exit your application immediately and without waiting for the user to confirm the shutdown. If your application does not exit within a reasonable amount of time (on the order of seconds), then the operating system will deem it to be non-responsive and will likely kill its process (and you won�t have any opportunity to capture and handle this event).

Warning (LabVIEW 7.x bug)

It has been mentioned by some LabVIEW users that there is a bug in LabVIEW 7.x that causes the OS shutdown to be aborted (on Windows, at least). However, this appears to be fixed in LabVIEW 8.0 and the technique mentioned in this article appears to work just fine on all OS’es.

So, if it is important you that your built LabVIEW application shuts down gracefully (and I hope it is), make sure that you have implemented a controlled, programmatic handling of the Application Exit? event. This valuable technique is often overlooked, but can make a tremendous difference in how your software runs and how professional your software is perceived to be, by your end users. And, if you happen to be writing software that controls hardware (as is the case for many LabVIEW applications), it just might make your software safer for your users.

Do you want to discuss this article or other related LabVIEW topics? Start a thread in the Application Builder, Installers, and Code Distribution forum at LAVA.

    July 10, 2006 | 5:27 am


    Believe it or not, I’ve been using this method of shutting down my built EXEs for a couple of years now. I forget how I found out about it, but it’s nice to know from one of the LV experts that I’m doing something right and of professional quality. :D

    August 1, 2006 | 9:52 am

    On a recent info-LabVIEW thread, it was mentioned that there is a bug in LabVIEW 7.x that causes the OS shutdown to be aborted (on Windows, at least). However, this appears to be fixed in LabVIEW 8.0 and the technique mentioned in this article appears to work just fine on all OS’es.

    November 16, 2006 | 9:23 am

    There are changes to this particular “Application Exit” event as of LV 8.2. Referring to page 10 of the LabVIEW 8.2 upgrade notes (see

    “The Application Instance Close and Application Instance Close?
    events replace the Application Exit and Application Exit? events.
    When you use the Application Instance Close event in a VI running
    outside a LabVIEW project, LabVIEW generates the event when you
    quit LabVIEW through the user interface or programmatically.
    LabVIEW generates the Application Instance Close? event when you
    quit LabVIEW through the user interface. When you register the
    Application Instance Close and Application Instance Close? events for
    a VI running within a LabVIEW project, LabVIEW generates the
    events when the application instance closes or when you quit

Sorry, the comment form is closed at this time.

Bad Behavior has blocked 778 access attempts in the last 7 days.