Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
1 ratings:
 3 out of 5     Rate this Document

Executing a Code Module Called by TestStand in an STA Thread

Primary Software: TestStand
Primary Software Version: 3.0
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem:
My code module displays a window containing an ActiveX control. I know that for my module to correctly display the ActiveX control, it must be launched in a thread initialized as STA (single-threaded apartment). In order to accomplish this, I placed the TestStand step calling my module in a subsequence. I then configured a Sequence Call step to call my subsequence in a single-threaded apartment thread.

However, when the Sequence Call step creates the new thread and my code module is executed, I experience the same problems, as if my code module was ran in a thread that was not initialized as single-threaded apartment. Why is this and how can I make it work?

Solution:
By default, TestStand initializes new executions and threads to use the multi-threaded apartment model. Thus, if your step's load option is set to Preload when execution begins (which is the default setting), TestStand will load its code module in the multi-threaded apartment (MTA) thread that is created when the execution starts. Therefore, for a code module to execute in a single-threaded apartment (STA) thread created by a Sequence Call step in TestStand, you need to make sure that it is loaded after the STA thread is created. You can accomplish this by configuring the step calling your code module to load it dynamically:
  1. Double-click on the step calling your code module to open its Properties window.

  2. Click the Run Options tab and select Load Dynamically as the Load option.

  3. Optionally, you can select Unload after step executes as the Unload option.
Note: You need to do this in every step that needs to be executed in an STA thread.

Related Links:
KnowledgeBase 30E9LEEV: New Sequence Adapter COM Multithreading Setting in TestStand 3.0
KnowledgeBase 2JIC15IJ: DLL Works When Called outside of TestStand but Not When Called from TestStand
Developer Zone Example: Displaying a Dialog With ActiveX Controls On It From a DLL Called by TestStand

Attachments:





Report Date: 05/19/2004
Last Updated: 09/05/2007
Document ID: 39IE8AMT

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit