Export (0) Print
Expand All

ExecutionContext Class

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

System.Object
  System.Threading.ExecutionContext

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

[SerializableAttribute]
public sealed class ExecutionContext : IDisposable, 
	ISerializable

The ExecutionContext type exposes the following members.

  NameDescription
Public methodStatic memberCaptureCaptures the execution context from the current thread.
Public methodCreateCopyCreates a copy of the current execution context.
Public methodDisposeReleases all resources used by the current instance of the ExecutionContext class.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetObjectDataSets the specified SerializationInfo object with the logical context information needed to recreate an instance of the current execution context.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodStatic memberIsFlowSuppressedIndicates whether the flow of the execution context is currently suppressed.
Public methodStatic memberRestoreFlowRestores the flow of the execution context across asynchronous threads.
Public methodStatic memberRunRuns a method in a specified execution context on the current thread.
Public methodStatic memberSuppressFlowSuppresses the flow of the execution context across asynchronous threads.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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