How to Direct TestStand to Cleanup Using an Emergency Stop Thread

Updated Nov 3, 2026

Environment

Software

  • TestStand

When executing automated test sequences in NI TestStand, it is often necessary to run a concurrent monitoring thread that continuously checks for an emergency stop (E-stop) condition. Examples include a user-initiated stop request from the operator interface or an external stop signal received from a PLC. Upon detecting an E-stop event, the test system should safely terminate sequence execution and transition to the Cleanup step group.

Directly terminating an execution or modifying a parent sequence context from an asynchronous thread is generally not recommended. Such actions can interrupt normal execution flow, prevent proper report generation, and cause failures in Process Model plugins or other post-execution activities.

This article describes an approach for implementing an asynchronous monitoring thread that communicates E-stop status through a File Global variable. The main execution thread then performs a controlled transition to the Cleanup step group through the SequenceFilePostStep callback. By ensuring that execution control remains within the primary sequence context, this method helps preserve Process Model integrity and supports orderly shutdown of the test sequence.

While this approach provides a reliable mechanism for handling E-stop events, it is important to note that TestStand offers multiple supported methods for gracefully terminating an execution. The technique presented in this article represents one possible implementation and is not intended to be an exhaustive list of all available solutions.

Configure Asynchronous E-Stop Monitoring

This implementation uses a separate monitoring thread to detect an E-stop condition and update a File Global variable. The SequenceFilePostStep callback evaluates this variable after each step in the main execution and redirects execution to the Cleanup step group when an emergency stop is requested.

1. Create the Monitoring Sequence

  1. Open your sequence file in NI TestStand Sequence Editor.
  2. In the Sequences pane, right-click and select New Sequence to add new sequence. Rename the new sequence to "Monitor EStop". 
  3. Return to the MainSequence in Sequences pane, add a Sequence Call step and rename it to "Monitor Stop in New Thread".
    1. At the Step Settings,
      1. enable Use Current File
      2. set Sequence to Monitor EStop
      3.  Under Execution Options,  select Use New Thread as below.

2. Implement E-Stop Detection

  1. In the Sequences pane, click on Monitor EStop, add in your code that use to monitor your manual stop. For example, in this article, we will demonstrate how to use a Message Popup to act as an emergency stop button.
    1. Add a Message Popup step into Main.
    2. Set the Message Expression to "Stop the test?"
    3. Change the Button Label Expressions on Button 1 to "Yes" and Button 2 to "No".
    4. Change the Button Options on Cancel Button to Button 2.
    5. At the Properties tab, select Expressions and enter the expression as below at Post-Expression to set the condition when the button on the Message Popup is pressed. 
      FileGlobals.ManualStop= Step.Result.ButtonHit == 1 ? True: False
    6. Right-click on the FileGlobals.ManualStop and select Create "FileGlobals.ManualStop" >> Boolean to create the variable under FileGlobals Variables group.

Note: In a production system, the E-stop condition may be monitored through a PLC input, digital I/O line, shared variable, or custom code module. If continuous monitoring is required, implement a While Loop that periodically checks the stop condition and exits when an E-stop request is detected.

3. Add the SequenceFilePostStep Callback

  1. At the Sequences pane, right-click and select Sequences File Callbacks to launch the callbacks dialog box.
  2. Tick the box of SequenceFilePostStep and click OK to add the sequence into the client sequence file.

4. Redirect Execution to Cleanup

  1. At the SequenceFilePostStep sequence, add an If statement and set the condition as below:
    FileGlobals.ManualStop == True
  2. Add a Statement inside the If statement and set the Expression as below.
    RunState.Caller.GotoCleanup = True
    When this statement executes, TestStand completes the current step and transfers execution to the Cleanup step group of the calling sequence.

5. Execute the Sequence

  1. In your MainSequence sequence, add in your desired steps while E-Stop button is being monitored at a different thread. In this example, we are adding Wait and empty Action steps to examine the result. 
  2. Save your sequence file.
  3. Run the sequence and trigger the E-stop condition.
  4. Verify that the execution exits the normal flow and enters the Cleanup step group gracefully.

With this configuration, the monitoring thread only updates the shared File Global status, while the primary execution thread retains control over execution flow. This avoids the risks associated with terminating an execution from an asynchronous thread and helps ensure proper report generation, Process Model operation, and orderly execution shutdown.