10-06-2010 02:25 PM
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.
Solved! Go to Solution.
10-07-2010 09:34 AM
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,
-Doug
10-13-2010 09:01 AM
Doug,
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.
Regards,
Jesse