Assembly: mscorlib (in mscorlib.dll)
[ComVisibleAttribute(true)] [AttributeUsageAttribute(AttributeTargets.Method)] public sealed class MTAThreadAttribute : Attribute
/** @attribute ComVisibleAttribute(true) */ /** @attribute AttributeUsageAttribute(AttributeTargets.Method) */ public final class MTAThreadAttribute extends Attribute
ComVisibleAttribute(true) AttributeUsageAttribute(AttributeTargets.Method) public final class MTAThreadAttribute extends Attribute
Apply this attribute to the entry point method (the Main() method in C# and Visual Basic). It has no effect on other methods. To set the apartment state of threads you start in your code, use the Thread.SetApartmentState method before starting the thread.
In the .NET Framework versions 1.0 and 1.1, set the Thread.ApartmentState property before starting the thread.
COM threading models only pertain to applications that use COM interop. Using this attribute in an application that does not use COM interop has no effect.
The COM threading model can be set to single-threaded apartment or multithreaded apartment. The application thread is only initialized for COM interop if the thread actually makes a call to a COM component. If COM interop is not used, then the thread is not initialized.
In the .NET Framework versions 1.0 and 1.1, use this attribute on Main() instead of setting the Thread.ApartmentState property on the first line of code, to ensure that the threading model is set before any startup code is executed.
In the .NET Framework version 2.0, new threads are initialized as ApartmentState.MTA if their apartment state has not been set before they are started. The main application thread is initialized to ApartmentState.MTA by default. You can no longer set the main application thread to ApartmentState.STA by setting the Thread.ApartmentState property on the first line of code. Use the STAThreadAttribute instead.
In the .NET Framework version 2.0, you can also specify the COM threading model for a C++ application using the /CLRTHREADATTRIBUTE (Set CLR Thread Attribute) linker option.
ASP.NET applications should set the ASPCompat attribute of the [<topic://cpconpage>] directive to true, to force the page to be serviced by the STA thread pool.
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter EditionThe Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.