AsyncLocal<T> Class
Represents ambient data that is local to a given asynchronous control flow, such as an asynchronous method.
Assembly: mscorlib (in mscorlib.dll)
| Name | Description | |
|---|---|---|
![]() | AsyncLocal<T>() | Instantiates an AsyncLocal<T> instance that does not receive change notifications. |
![]() | AsyncLocal<T>(Action<AsyncLocalValueChangedArgs<T>>^) | Instantiates an AsyncLocal<T> local instance that receives change notifications. |
| Name | Description | |
|---|---|---|
![]() | Value | Gets or sets the value of the ambient data. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object^) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetType() | |
![]() | ToString() | 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>.
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.

