ExecutionContext ExecutionContext ExecutionContext ExecutionContext Class

Definition

Manages the execution context for the current thread. This class cannot be inherited.

public ref class ExecutionContext sealed : IDisposable, System::Runtime::Serialization::ISerializable
public sealed class ExecutionContext : IDisposable, System.Runtime.Serialization.ISerializable
type ExecutionContext = class
    interface IDisposable
    interface ISerializable
Public NotInheritable Class ExecutionContext
Implements IDisposable, ISerializable
Inheritance
ExecutionContextExecutionContextExecutionContextExecutionContext
Implements

Remarks

The 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 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 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 UnsafeQueueUserWorkItem method), which do not transfer the compressed stack. Wherever the compressed stack flows, the managed principal, synchronization, locale, and user context also flow. The ExecutionContext class provides the Capture and CreateCopy methods to get the execution context and the Run method to set the execution context for the current thread.

An 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 ExecutionContext from one thread to another, make a copy of the ExecutionContext.

Internally, the ExecutionContext stores all data that is associated with the LogicalCallContext. This allows the LogicalCallContext data to be propagated when the ExecutionContext is copied and transferred.

Methods

Capture() Capture() Capture() Capture()

Captures the execution context from the current thread.

CreateCopy() CreateCopy() CreateCopy() CreateCopy()

Creates a copy of the current execution context.

Dispose() Dispose() Dispose() Dispose()

Releases all resources used by the current instance of the ExecutionContext class.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

Sets the specified SerializationInfo object with the logical context information needed to recreate an instance of the current execution context.

GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
IsFlowSuppressed() IsFlowSuppressed() IsFlowSuppressed() IsFlowSuppressed()

Indicates whether the flow of the execution context is currently suppressed.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
RestoreFlow() RestoreFlow() RestoreFlow() RestoreFlow()

Restores the flow of the execution context across asynchronous threads.

Run(ExecutionContext, ContextCallback, Object) Run(ExecutionContext, ContextCallback, Object) Run(ExecutionContext, ContextCallback, Object) Run(ExecutionContext, ContextCallback, Object)

Runs a method in a specified execution context on the current thread.

SuppressFlow() SuppressFlow() SuppressFlow() SuppressFlow()

Suppresses the flow of the execution context across asynchronous threads.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to