ThreadLocal<T> ThreadLocal<T> ThreadLocal<T> ThreadLocal<T> Constructors

Definition

Overloads

ThreadLocal<T>() ThreadLocal<T>() ThreadLocal<T>()

Initializes the ThreadLocal<T> instance.

ThreadLocal<T>(Boolean) ThreadLocal<T>(Boolean) ThreadLocal<T>(Boolean) ThreadLocal<T>(Boolean)

Initializes the ThreadLocal<T> instance and specifies whether all values are accessible from any thread.

ThreadLocal<T>(Func<T>) ThreadLocal<T>(Func<T>) ThreadLocal<T>(Func<T>) ThreadLocal<T>(Func<T>)

Initializes the ThreadLocal<T> instance with the specified valueFactory function.

ThreadLocal<T>(Func<T>, Boolean) ThreadLocal<T>(Func<T>, Boolean) ThreadLocal<T>(Func<T>, Boolean) ThreadLocal<T>(Func<T>, Boolean)

Initializes the ThreadLocal<T> instance with the specified valueFactory function and a flag that indicates whether all values are accessible from any thread.

ThreadLocal<T>() ThreadLocal<T>() ThreadLocal<T>()

Initializes the ThreadLocal<T> instance.

public:
 ThreadLocal();
public ThreadLocal ();
Public Sub New ()

Remarks

The default value of T is used to initialize the instance when Value is accessed for the first time.

This constructor is equivalent to calling the ThreadLocal<T>(Boolean) constructor with a value of false for the trackAllValues argument.

See Also

ThreadLocal<T>(Boolean) ThreadLocal<T>(Boolean) ThreadLocal<T>(Boolean) ThreadLocal<T>(Boolean)

Initializes the ThreadLocal<T> instance and specifies whether all values are accessible from any thread.

public:
 ThreadLocal(bool trackAllValues);
public ThreadLocal (bool trackAllValues);
new System.Threading.ThreadLocal<'T> : bool -> System.Threading.ThreadLocal<'T>
Public Sub New (trackAllValues As Boolean)
Parameters
trackAllValues
Boolean Boolean Boolean Boolean

true to track all values set on the instance and expose them through the Values property; false otherwise.

Remarks

If trackAllValues is false, only the value of this instance for the current thread is accessible. Attempting to use the Values property to retrieve all values throws an InvalidOperationException exception.

ThreadLocal<T>(Func<T>) ThreadLocal<T>(Func<T>) ThreadLocal<T>(Func<T>) ThreadLocal<T>(Func<T>)

Initializes the ThreadLocal<T> instance with the specified valueFactory function.

public:
 ThreadLocal(Func<T> ^ valueFactory);
public ThreadLocal (Func<T> valueFactory);
new System.Threading.ThreadLocal<'T> : Func<'T> -> System.Threading.ThreadLocal<'T>
Public Sub New (valueFactory As Func(Of T))
Parameters
valueFactory
Func<T>

The Func<TResult> invoked to produce a lazily-initialized value when an attempt is made to retrieve Value without it having been previously initialized.

Exceptions

valueFactory is a null reference (Nothing in Visual Basic).

See Also

ThreadLocal<T>(Func<T>, Boolean) ThreadLocal<T>(Func<T>, Boolean) ThreadLocal<T>(Func<T>, Boolean) ThreadLocal<T>(Func<T>, Boolean)

Initializes the ThreadLocal<T> instance with the specified valueFactory function and a flag that indicates whether all values are accessible from any thread.

public:
 ThreadLocal(Func<T> ^ valueFactory, bool trackAllValues);
public ThreadLocal (Func<T> valueFactory, bool trackAllValues);
new System.Threading.ThreadLocal<'T> : Func<'T> * bool -> System.Threading.ThreadLocal<'T>
Public Sub New (valueFactory As Func(Of T), trackAllValues As Boolean)
Parameters
valueFactory
Func<T>

The Func<TResult> invoked to produce a lazily-initialized value when an attempt is made to retrieve Value without it having been previously initialized.

trackAllValues
Boolean Boolean Boolean Boolean

true to track all values set on the instance and expose them through the Values property; false otherwise.

Exceptions

valueFactory is a null reference (Nothing in Visual Basic).

Remarks

If trackAllValues is false, only the value of this instance for the current thread is accessible. Attempting to use the Values property to retrieve all values throws an InvalidOperationException exception.

Applies to