The following Example Program demonstrates how to share/pass a .NET Object between a TestStand execution and a custom user interface written in .NET.
.NET Objects created in a TestStand execution cannot be directly accessed from a TestStand user interface. This is due to the fact that objects created in the sequence are in a separate Application Domain than the User Interface. .NET objects exist in a particular Application Domain, and an object is only accessible within the Application Domain in which it is created. Because TestStand Creates a new application domain for executing sequence files, the UI cannot directly access the object.
For more information on Application Domains, refer to the article below:
To address this limitation, you can access the object reference through the TestStand API to access the object in the TestStand Execution application domain rather than the UI application domain. To use this approach:
Create an instance of a .NET object in TestStand and store the reference in a variable, such as a Local.
Call a method of the object from the sequence.
Send a UIMessage from the sequence to the Operator Interface.
Implement a UI message handler in the UI which receives this message, gets the reference to the object, casts the object to the correct type, and calls a method of the object.
When using this approach, consider:
Set the lease time on the object by overriding InitializeLifetimeService() in the object so that it doesn't timeout for cross-appdomain access.
For an object to be used in this manner, it must either be derived from MarshalByRefObject or be serializable. (If it is serializable, then copies are made rather than accessing a reference to the original.)
Any objects you pass in or out of the members of this marshaled object need to be basic types, derived from MarshalByRefObject themselves, or serializable.