Programmatically Exit or Close a LabVIEW Executable

Updated Oct 25, 2023

Environment

Software

  • LabVIEW

This article explains how a LabVIEW executable can be closed automatically once it is finished running or meets specified conditions. 

For this, the Quit LabVIEW function can be used which is located in the Functions Palette under Programming » Application Control.


If the Quit LabVIEW function is called within the development environment, it will close the LabVIEW Development Environment. In order to make this function run only in the executable version of the application, it should be enclosed in a Conditional Disable Structure from the Functions Palette under Programming » Structures.


The Conditional Disable Structure needs to be configured. The steps to configure depend on the LabVIEW version:
 

LabVIEW 2009 or more recent

LabVIEW 2009 added a conditional symbol that allows the application to determine if it is running inside the development environment or not.
  1. Insert a Conditional Disable Structure into your code.
  2. Right-click it and pick Add Subdiagram After.
  3. In the Symbols(s) field, choose RUN_TIME_ENGINE.
  4. Leave the center field as ==.
  5. In the Value(s) field, type True.
  1. Click OK.
  2. Move the Quit LabVIEW function into the newly created subdiagram, leaving the Default case empty.

 

LabVIEW 8.6 or earlier

In LabVIEW 8.6, you must define a custom conditional symbol. Note: To be able to do so, your VI must be part of a project.
  1. Insert a Conditional Disable Structure into your code.
  2. Right-click it and pick Add Subdiagram After.
  3. In the Symbol(s) field, type DEPLOY.
  4. Leave the center field as ==.
  5. In the Value(s) field, type TRUE.
  6. Select OK.
  1. Choose Project » Properties.
  2. Select Conditional Disable Symbols in the Category column.
  3. Create a New Symbol by defining DEPLOY symbol. If you are still developing your application, set the New Value as FALSE. If your application is ready to build, set New Value as TRUE. Note: Before building your executable, ensure that you change the DEPLOY symbol to True in order to enable the Quit LabVIEW function in the deployed application.
  1. Move the Quit LabVIEW function into the newly created subdiagram, leaving the Default case empty.

Be careful when using the Quit LabVIEW function. If there are open references, session, or queues that are examined in parallel while this function is run, they will be terminated, and can cause crashes or access violations. These crashes might not happen every time calling the Quit LabVIEW function, depending on the exact order your LabVIEW code is executed depending on the LabVIEW compiler and underlying operating system.

Consider the following code. It works about half the time depending on the computer:

Best practices of this VI include calling it at the very end of your program, and ensure all data flows and concatenates to a single point, prior to this call, including a wait function prior to this, and closing the Front Panel Programmatically .