This documentation is archived and is not being maintained.

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:

         <ExecutionThread apartmentState="MTA" />
  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.