Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

How to: Run Unit Tests in MTA mode

You might want to run your tests in MTA mode, using multithreaded apartments, because of the methods that you have used to write your tests. For example, if you use a method such as WaitHandle.WaitAll that is not supported with STA (single threaded apartment), you must run your unit tests in MTA mode. By default unit tests are run using STA.

To modify your test settings file to run your unit tests in MTA mode, follow these steps:

To run unit tests in MTA mode

  1. To open the solution that contains the unit tests that you want to run in MTA mode, click File, point to Open, and then click Project/Solution.

    The Open Project dialog box is displayed.

  2. Select your solution, and then click Open.

  3. To modify the test settings file, open Solution Items, right-click the test settings file, and point to Open With. Select a text or XML editor.

    The file is displayed in the editor.

  4. To set the unit tests to run in MTA mode, add the MTA mode attribute to the Execution element as shown in the following example:

    <Execution>
         <ExecutionThread apartmentState="MTA" />
    </Execution>
    
  5. Save the test settings file.

  6. Exit and restart Microsoft Visual Studio 2010.

  7. Reload your solution and run your tests.

    Your tests are displayed in the Test Results window when they run.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft