Edit

Share via


Thread.ApartmentState Property

Definition

Caution

The ApartmentState property has been deprecated. Use GetApartmentState, SetApartmentState or TrySetApartmentState instead.

Caution

The ApartmentState property has been deprecated. Use GetApartmentState, SetApartmentState or TrySetApartmentState instead.

Gets or sets the apartment state of this thread.

public:
 property System::Threading::ApartmentState ApartmentState { System::Threading::ApartmentState get(); void set(System::Threading::ApartmentState value); };
[System.Obsolete("The ApartmentState property has been deprecated. Use GetApartmentState, SetApartmentState or TrySetApartmentState instead.")]
public System.Threading.ApartmentState ApartmentState { get; set; }
[System.Obsolete("The ApartmentState property has been deprecated.  Use GetApartmentState, SetApartmentState or TrySetApartmentState instead.", false)]
public System.Threading.ApartmentState ApartmentState { get; set; }
public System.Threading.ApartmentState ApartmentState { get; set; }
[<System.Obsolete("The ApartmentState property has been deprecated. Use GetApartmentState, SetApartmentState or TrySetApartmentState instead.")>]
member this.ApartmentState : System.Threading.ApartmentState with get, set
[<System.Obsolete("The ApartmentState property has been deprecated.  Use GetApartmentState, SetApartmentState or TrySetApartmentState instead.", false)>]
member this.ApartmentState : System.Threading.ApartmentState with get, set
member this.ApartmentState : System.Threading.ApartmentState with get, set
Public Property ApartmentState As ApartmentState

Property Value

One of the ApartmentState values. The initial value is Unknown.

Attributes

Exceptions

An attempt is made to set this property to a state that is not a valid apartment state (a state other than single-threaded apartment (STA) or multithreaded apartment (MTA)).

Remarks

The ApartmentState property is obsolete. The non-obsolete alternatives are the GetApartmentState method to retrieve the apartment state and the SetApartmentState method to set the apartment state.

Important

New threads are initialized as ApartmentState.MTA if their apartment state has not been set before they're started. The main application thread is initialized to ApartmentState.MTA by default.

You can specify the COM threading model for a C++ application using the /CLRTHREADATTRIBUTE (Set CLR Thread Attribute) linker option.

Applies to

See also