ThreadStaticAttribute Class
This page is specific to:.NET Framework Version:1.12.03.03.5Silverlight 34.0
.NET Framework Class Library
ThreadStaticAttribute Class

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

For a list of all members of this type, see ThreadStaticAttribute Members.

System.Object
   System.Attribute
      System.ThreadStaticAttribute

[Visual Basic]
<AttributeUsage(AttributeTargets.Field)>
<Serializable>
Public Class ThreadStaticAttribute
   Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.Field)]
[Serializable]
public class ThreadStaticAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::Field)]
[Serializable]
public __gc class ThreadStaticAttribute : public Attribute
[JScript]
public
   AttributeUsage(AttributeTargets.Field)
 Serializable
class ThreadStaticAttribute extends Attribute

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.

Remarks

A static (Shared in Visual Basic) 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 a 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.

Requirements

Namespace: System

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: Mscorlib (in Mscorlib.dll)

See Also

ThreadStaticAttribute Members | System Namespace | Attribute | Thread | Extending Metadata Using Attributes | Threading

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View