System.Threading.Thread.SetApartmentState Method

Sets the apartment state of a thread before it is started.

Syntax

public void SetApartmentState (ApartmentState state)

Parameters

state
The new apartment state.

Remarks

New threads are initialized as ApartmentState.MTA if their apartment state has not been set before they are started. Apartment state must be set before a thread is started.

Note:

The main application thread is initialized to ApartmentState.MTA by default. The only way to set the apartment state of the main application thread to ApartmentState.STA is to apply the STAThreadAttribute attribute to the entry point method.

The Thread.SetApartmentState(ApartmentState) method, along with the Thread.GetApartmentState method and the Thread.TrySetApartmentState(ApartmentState) method, replaces the Thread.ApartmentState property.

Requirements

Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0