Editar

Compartir vía


ThreadLocal<T> Constructors

Definition

Initializes a ThreadLocal<T> instance.

Overloads

ThreadLocal<T>()

Initializes the ThreadLocal<T> instance.

ThreadLocal<T>(Boolean)

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

ThreadLocal<T>(Func<T>)

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

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>()

Source:
ThreadLocal.cs
Source:
ThreadLocal.cs
Source:
ThreadLocal.cs

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

Applies to

ThreadLocal<T>(Boolean)

Source:
ThreadLocal.cs
Source:
ThreadLocal.cs
Source:
ThreadLocal.cs

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

true to track all values set on the instance and expose them through the Values property; false otherwise. When set to true, a value stored from a given thread will be available through Values even after that thread has exited.

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

ThreadLocal<T>(Func<T>)

Source:
ThreadLocal.cs
Source:
ThreadLocal.cs
Source:
ThreadLocal.cs

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

Applies to

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

Source:
ThreadLocal.cs
Source:
ThreadLocal.cs
Source:
ThreadLocal.cs

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

true to track all values set on the instance and expose them through the Values property; false otherwise. When set to true, a value stored from a given thread will be available through Values even after that thread has exited.

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