NI TestStand

Showing results for 
Search instead for 
Did you mean: 

Call .NET code in MTA from TestStand

Go to solution

Is it possible to create a custom step to call .NET code that runs in a multi-threaded apartment model (MTA).  By default, as of TestStand 4.2.1 when I run a step it is running that code in a single threaded apartment model (STA).  The code I'm running somewhat functions, but some aspects fail because of the incorrect apartment.


I am creating custom step types and calling the .NET code using the .NET adapter in post-steps.

0 Kudos
Message 1 of 3
Accepted by topic author Hesse34

Actually, MTA is the default for teststand execution threads. The one exception to that is edit substeps. The reason is that edit substeps usually display dialogs and in order for dialogs that contain ActiveX controls to work, they must run in an STA thread. If you are running your code with an edit substep and want an MTA thread then you must create a new thread in your code module that is an MTA thread and hand off the work to that thread and wait for it to complete in the original thread that teststand calls into your code with.


post substeps on the other hand are run in whatever thread is the current execution thread. These threads are MTA by default. STA threads can be created in TestStand using the sequence call step with the "new thread" or "new execution" option and checking the "Use Single-Threaded Apartment" checkbox on the advanced pane of the sequence call settings panel.


Hope this helps,


0 Kudos
Message 2 of 3



Thanks for the detailed explanation.  You were absolutely correct that the thread is an MTA thread.  I found the problem deeper in my code, so things look good.




0 Kudos
Message 3 of 3