Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

AsyncLocal<T> Class

.NET Framework (current version)
 

Represents ambient data that is local to a given asynchronous control flow, such as an asynchronous method.

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

System::Object
  System.Threading::AsyncLocal<T>

generic<typename T>
public ref class AsyncLocal sealed 

Type Parameters

T

The type of the ambient data.

NameDescription
System_CAPS_pubmethodAsyncLocal<T>()

Instantiates an AsyncLocal<T> instance that does not receive change notifications.

System_CAPS_pubmethodAsyncLocal<T>(Action<AsyncLocalValueChangedArgs<T>>^)

Instantiates an AsyncLocal<T> local instance that receives change notifications.

NameDescription
System_CAPS_pubpropertyValue

Gets or sets the value of the ambient data.

NameDescription
System_CAPS_pubmethodEquals(Object^)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

Because the task-based asynchronous programming model tends to abstract the use of threads, AsyncLocal<T> instances can be used to persist data across threads.

The AsyncLocal<T> class also provides optional notifications when the value associated with the current thread changes, either because it was explicitly changed by setting the Value property, or implicitly changed when the thread encountered an await or other context transition.

The following example uses the AsyncLocal<T> class to persist a string value across an asynchronous flow. It also contrasts the use of AsyncLocal<T> with ThreadLocal<T>.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 10
.NET Framework
Available since 4.6

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

Return to top
Show: