Indicates that the value of a static field is unique for each thread.
Namespace:
System
Assembly:
mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
<SerializableAttribute> _
<AttributeUsageAttribute(AttributeTargets.Field, Inherited := False)> _
<ComVisibleAttribute(True)> _
Public Class ThreadStaticAttribute _
Inherits Attribute
Dim instance As ThreadStaticAttribute
[SerializableAttribute]
[AttributeUsageAttribute(AttributeTargets.Field, Inherited = false)]
[ComVisibleAttribute(true)]
public class ThreadStaticAttribute : Attribute
[SerializableAttribute]
[AttributeUsageAttribute(AttributeTargets::Field, Inherited = false)]
[ComVisibleAttribute(true)]
public ref class ThreadStaticAttribute : public Attribute
public class ThreadStaticAttribute extends Attribute
A static field marked with ThreadStaticAttribute is not shared between threads. Each executing thread has a separate instance of the field, and independently sets and gets values for that field. If the field is accessed on a different thread, it will contain a different value.
Note: |
|---|
Do not specify initial values for fields marked with ThreadStaticAttribute, because such initialization occurs only once, when the class constructor executes, and therefore affects only one thread. If you do not specify an initial value, you can rely on the field being initialized to its default value if it is a value type, or to nullNothingnullptra null reference (Nothing in Visual Basic) if it is a reference type. |
Use this attribute as it is, and do not derive from it. The following is an example of ThreadStaticAttribute syntax:
[ThreadStatic]
static int value;
<ThreadStatic> _
Shared value As Integer
For more information about using attributes, see Extending Metadata Using Attributes.
System..::.Object
System..::.Attribute
System..::.ThreadStaticAttribute
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
Other Resources