mscorlib(4.0.0.0) API with additions
AsyncLocal.cs
1 using System.Security;
2 
3 namespace System.Threading
4 {
7  [__DynamicallyInvokable]
8  public sealed class AsyncLocal<T> : IAsyncLocal
9  {
10  [SecurityCritical]
11  private readonly Action<AsyncLocalValueChangedArgs<T>> m_valueChangedHandler;
12 
15  [__DynamicallyInvokable]
16  public T Value
17  {
18  [SecuritySafeCritical]
19  [__DynamicallyInvokable]
20  get
21  {
22  object localValue = ExecutionContext.GetLocalValue(this);
23  if (localValue != null)
24  {
25  return (T)localValue;
26  }
27  return default(T);
28  }
29  [SecuritySafeCritical]
30  [__DynamicallyInvokable]
31  set
32  {
33  ExecutionContext.SetLocalValue(this, value, m_valueChangedHandler != null);
34  }
35  }
36 
38  [__DynamicallyInvokable]
39  public AsyncLocal()
40  {
41  }
42 
45  [SecurityCritical]
46  [__DynamicallyInvokable]
47  public AsyncLocal(Action<AsyncLocalValueChangedArgs<T>> valueChangedHandler)
48  {
49  m_valueChangedHandler = valueChangedHandler;
50  }
51 
52  [SecurityCritical]
53  void IAsyncLocal.OnValueChanged(object previousValueObj, object currentValueObj, bool contextChanged)
54  {
55  T previousValue = (previousValueObj == null) ? default(T) : ((T)previousValueObj);
56  T currentValue = (currentValueObj == null) ? default(T) : ((T)currentValueObj);
57  m_valueChangedHandler(new AsyncLocalValueChangedArgs<T>(previousValue, currentValue, contextChanged));
58  }
59  }
60 }
AsyncLocal(Action< AsyncLocalValueChangedArgs< T >> valueChangedHandler)
Instantiates an T:System.Threading.AsyncLocal`1 local instance that receives change notifications.
Definition: AsyncLocal.cs:47
Definition: __Canon.cs:3
Represents ambient data that is local to a given asynchronous control flow, such as an asynchronous m...
Definition: AsyncLocal.cs:8
delegate void Action()
Encapsulates a method that has no parameters and does not return a value.
Manages the execution context for the current thread. This class cannot be inherited.
T Value
Gets or sets the value of the ambient data.
Definition: AsyncLocal.cs:17
AsyncLocal()
Instantiates an T:System.Threading.AsyncLocal`1 instance that does not receive change notifications.
Definition: AsyncLocal.cs:39
The class that provides data change information to T:System.Threading.AsyncLocal`1 instances that reg...