Expand
ThreadStaticAttribute Class

Indicates that the value of a static field is unique for each thread.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
Syntax

'Declaration

<SerializableAttribute> _
<AttributeUsageAttribute(AttributeTargets.Field, Inherited := False)> _
<ComVisibleAttribute(True)> _
Public Class ThreadStaticAttribute _
	Inherits Attribute
Remarks

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.

NoteNote

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 Nothing 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.

Inheritance Hierarchy

System.Object
  System.Attribute
    System.ThreadStaticAttribute
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Community ContentAdd
Page view tracker