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 , pressing the 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 , 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.
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.
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.
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.
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.