NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Shutdown TestStand Engine

If I start the TestStand Engine with

axApplicationMgr1.Start();

and Stop it with:

axApplicationMgr1.Shutdown();

TestStand is warning every time, that there are unreleased Executions, Files, Type Definitions and Objects... why?

I'm just doing the start and the shutdown, without open any file oder starting any executions or anything else.

I have attached a simple sample application, written in C# and using TestStand 4.0

0 Kudos
Message 1 of 3
(3,535 Views)
I've forgotten the attachment
0 Kudos
Message 2 of 3
(3,528 Views)
To avoid those warnings, you need to add an ApplicationMgr.ExitApplication event handler such as the following one I copied from the simple C# UI example:
 

private void axApplicationMgr_ExitApplication(object sender, System.EventArgs e)

{

GC.Collect(); // force .net garbage collection to ensure ensure all TestStand objects are freed before the TestStand engine unloads

GC.WaitForPendingFinalizers();

}

 
The reason this is needed is that when an ActiveX control sends an event via a .net interop assembly, any ActiveX interface parameters are wrapped in .net classes even if the event is not used by the client .net application. Although the .net wrapper is not used once the event completes, it is not finalized until it is garbage collected. Thus, it keeps a reference to the ActiveX object it wraps, which in this case is an Execution.  When the engine shuts down, it tries to warn you if any TestStand objects have not been released on the assumption that this indicates a bug in your application. However, the engine has no way to determine that an ActiveX object has yet to be released only because an unreferenced .net wrapper has yet to be finalized. While some people like to categorize a call to GC.Collect as a bad practice, we have not found a detectable drawback to using it in this way to smooth the interaction with ActiveX APIs. When destruction order matters, there is really no other work around since you can't call Dispose on those objects that never reach your source code.
 
I recommend starting with the simple C# UI example and removing what you don't need (like the call to Close in the ExitApplication handler) instead starting from scratch.
0 Kudos
Message 3 of 3
(3,509 Views)