Indicates that the COM threading model for an application is single-threaded apartment (STA).
Namespace:
System
Assembly:
mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
<AttributeUsageAttribute(AttributeTargets.Method)> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class STAThreadAttribute _
Inherits Attribute
Dim instance As STAThreadAttribute
[AttributeUsageAttribute(AttributeTargets.Method)]
[ComVisibleAttribute(true)]
public sealed class STAThreadAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Method)]
[ComVisibleAttribute(true)]
public ref class STAThreadAttribute sealed : public Attribute
public final class STAThreadAttribute 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.
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, 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 @ Page directive to true, to force the page to be serviced by the STA thread pool.
System..::.Object
System..::.Attribute
System..::.STAThreadAttribute
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Reference