mscorlib(4.0.0.0) API with additions
System.Threading.ThreadLocal< T > Class Template Reference

Provides thread-local storage of data. More...

Inheritance diagram for System.Threading.ThreadLocal< T >:
[legend]
Collaboration diagram for System.Threading.ThreadLocal< T >:
[legend]

Public Member Functions

 ThreadLocal ()
 Initializes the T:System.Threading.ThreadLocal`1 instance. More...
 
 ThreadLocal (bool trackAllValues)
 Initializes the T:System.Threading.ThreadLocal`1 instance and specifies whether all values are accessible from any thread. More...
 
 ThreadLocal (Func< T > valueFactory)
 Initializes the T:System.Threading.ThreadLocal`1 instance with the specified valueFactory function. More...
 
 ThreadLocal (Func< T > valueFactory, bool trackAllValues)
 Initializes the T:System.Threading.ThreadLocal`1 instance with the specified valueFactory function and a flag that indicates whether all values are accessible from any thread. More...
 
void Dispose ()
 Releases all resources used by the current instance of the T:System.Threading.ThreadLocal`1 class. More...
 
override string ToString ()
 Creates and returns a string representation of this instance for the current thread. More...
 

Protected Member Functions

virtual void Dispose (bool disposing)
 Releases the resources used by this T:System.Threading.ThreadLocal`1 instance. More...
 

Properties

Value [get, set]
 Gets or sets the value of this instance for the current thread. More...
 
IList< T > Values [get]
 Gets a list for all of the values currently stored by all of the threads that have accessed this instance. More...
 
bool IsValueCreated [get]
 Gets whether P:System.Threading.ThreadLocal`1.Value is initialized on the current thread. More...
 

Detailed Description

Provides thread-local storage of data.

Template Parameters
TSpecifies the type of data stored per-thread.

Definition at line 13 of file ThreadLocal.cs.

Constructor & Destructor Documentation

◆ ThreadLocal() [1/4]

Initializes the T:System.Threading.ThreadLocal`1 instance.

Definition at line 251 of file ThreadLocal.cs.

◆ ThreadLocal() [2/4]

System.Threading.ThreadLocal< T >.ThreadLocal ( bool  trackAllValues)

Initializes the T:System.Threading.ThreadLocal`1 instance and specifies whether all values are accessible from any thread.

Parameters
trackAllValuestrue to track all values set on the instance and expose them through the P:System.Threading.ThreadLocal`1.Values property; false otherwise.

Definition at line 260 of file ThreadLocal.cs.

◆ ThreadLocal() [3/4]

System.Threading.ThreadLocal< T >.ThreadLocal ( Func< T >  valueFactory)

Initializes the T:System.Threading.ThreadLocal`1 instance with the specified valueFactory function.

Parameters
valueFactoryThe T:System.Func`1 invoked to produce a lazily-initialized value when an attempt is made to retrieve P:System.Threading.ThreadLocal`1.Value without it having been previously initialized.
Exceptions
T:System.ArgumentNullExceptionvalueFactory is a null reference (Nothing in Visual Basic).

Definition at line 270 of file ThreadLocal.cs.

◆ ThreadLocal() [4/4]

System.Threading.ThreadLocal< T >.ThreadLocal ( Func< T >  valueFactory,
bool  trackAllValues 
)

Initializes the T:System.Threading.ThreadLocal`1 instance with the specified valueFactory function and a flag that indicates whether all values are accessible from any thread.

Parameters
valueFactoryThe T:System.Func`1 invoked to produce a lazily-initialized value when an attempt is made to retrieve P:System.Threading.ThreadLocal`1.Value without it having been previously initialized.
trackAllValuestrue to track all values set on the instance and expose them through the P:System.Threading.ThreadLocal`1.Values property; false otherwise.
Exceptions
T:System.ArgumentNullExceptionvalueFactory is a null reference (Nothing in Visual Basic).

Definition at line 286 of file ThreadLocal.cs.

Member Function Documentation

◆ Dispose() [1/2]

void System.Threading.ThreadLocal< T >.Dispose ( )

Releases all resources used by the current instance of the T:System.Threading.ThreadLocal`1 class.

Implements System.IDisposable.

Definition at line 318 of file ThreadLocal.cs.

◆ Dispose() [2/2]

virtual void System.Threading.ThreadLocal< T >.Dispose ( bool  disposing)
protectedvirtual

Releases the resources used by this T:System.Threading.ThreadLocal`1 instance.

Parameters
disposingA Boolean value that indicates whether this method is being called due to a call to M:System.Threading.ThreadLocal`1.Dispose.

Definition at line 327 of file ThreadLocal.cs.

◆ ToString()

override string System.Threading.ThreadLocal< T >.ToString ( )

Creates and returns a string representation of this instance for the current thread.

Returns
The result of calling M:System.Object.ToString on the P:System.Threading.ThreadLocal`1.Value.
Exceptions
T:System.ObjectDisposedExceptionThe T:System.Threading.ThreadLocal`1 instance has been disposed.
T:System.NullReferenceExceptionThe P:System.Threading.ThreadLocal`1.Value for the current thread is a null reference (Nothing in Visual Basic).
T:System.InvalidOperationExceptionThe initialization function attempted to reference P:System.Threading.ThreadLocal`1.Value recursively.
T:System.MissingMemberExceptionNo default constructor is provided and no value factory is supplied.

Definition at line 361 of file ThreadLocal.cs.

Property Documentation

◆ IsValueCreated

bool System.Threading.ThreadLocal< T >.IsValueCreated
get

Gets whether P:System.Threading.ThreadLocal`1.Value is initialized on the current thread.

Returns
true if P:System.Threading.ThreadLocal`1.Value is initialized on the current thread; otherwise false.
Exceptions
T:System.ObjectDisposedExceptionThe T:System.Threading.ThreadLocal`1 instance has been disposed.

Definition at line 214 of file ThreadLocal.cs.

◆ Value

T System.Threading.ThreadLocal< T >.Value
getset

Gets or sets the value of this instance for the current thread.

Returns
Returns an instance of the object that this ThreadLocal is responsible for initializing.
Exceptions
T:System.ObjectDisposedExceptionThe T:System.Threading.ThreadLocal`1 instance has been disposed.
T:System.InvalidOperationExceptionThe initialization function attempted to reference P:System.Threading.ThreadLocal`1.Value recursively.
T:System.MissingMemberExceptionNo default constructor is provided and no value factory is supplied.

Definition at line 143 of file ThreadLocal.cs.

◆ Values

IList<T> System.Threading.ThreadLocal< T >.Values
get

Gets a list for all of the values currently stored by all of the threads that have accessed this instance.

Returns
A list for all of the values currently stored by all of the threads that have accessed this instance.
Exceptions
T:System.InvalidOperationExceptionValues stored by all threads are not available because this instance was initialized with the trackAllValues argument set to false in the call to a class constructor.
T:System.ObjectDisposedExceptionThe T:System.Threading.ThreadLocal`1 instance has been disposed.

Definition at line 179 of file ThreadLocal.cs.


The documentation for this class was generated from the following file: