See Also: ExecutionContext Members
The System.Threading.ExecutionContext class provides a single container for all information relevant to a logical thread of execution. This includes security context, call context, and synchronization context.
The System.Threading.ExecutionContext class provides the functionality for user code to capture and transfer this context across user-defined asynchronous points. The common language runtime ensures that the System.Threading.ExecutionContext is consistently transferred across runtime-defined asynchronous points within the managed process.
An execution context is the managed equivalent of a COM apartment. Within an application domain, the entire execution context must be transferred whenever a thread is transferred. This situation occurs during transfers made by the Thread.Start method, most thread pool operations, and Windows Forms thread marshaling through the Windows message pump. It does not occur in unsafe thread pool operations (such as the ThreadPool.UnsafeQueueUserWorkItem(WaitCallback, object) method), which do not transfer the compressed stack. Wherever the compressed stack flows, the managed principal, synchronization, locale, and user context also flow. The System.Threading.ExecutionContext class provides the ExecutionContext.Capture and ExecutionContext.CreateCopy methods to get the execution context and the ExecutionContext.Run(ExecutionContext, ContextCallback, object) method to set the execution context for the current thread.
An System.Threading.ExecutionContext that is associated with a thread cannot be set on another thread. Attempting to do so will result in an exception being thrown. To propagate the System.Threading.ExecutionContext from one thread to another, make a copy of the System.Threading.ExecutionContext.
Internally, the System.Threading.ExecutionContext stores all data that is associated with the System.Runtime.Remoting.Messaging.LogicalCallContext. This allows the System.Runtime.Remoting.Messaging.LogicalCallContext data to be propagated when the System.Threading.ExecutionContext is copied and transferred.