ExecutionContext ExecutionContext ExecutionContext ExecutionContext Class

定义

管理当前线程的执行上下文。Manages the execution context for the current thread. 此类不能被继承。This class cannot be inherited.

public ref class ExecutionContext sealed : IDisposable, System::Runtime::Serialization::ISerializable
[System.Serializable]
public sealed class ExecutionContext : IDisposable, System.Runtime.Serialization.ISerializable
type ExecutionContext = class
    interface IDisposable
    interface ISerializable
Public NotInheritable Class ExecutionContext
Implements IDisposable, ISerializable
继承
ExecutionContextExecutionContextExecutionContextExecutionContext
属性
实现

注解

ExecutionContext类为与执行的逻辑线程相关的所有信息提供单个容器。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.

ExecutionContext类提供用户代码用于跨用户定义的异步点捕获和传输此上下文的功能。The ExecutionContext class provides the functionality for user code to capture and transfer this context across user-defined asynchronous points. 公共语言运行时确保在托管ExecutionContext进程内的运行时定义的异步点之间一致传输。The common language runtime ensures that the ExecutionContext is consistently transferred across runtime-defined asynchronous points within the managed process.

执行上下文是 COM 单元的托管等效项。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. 这种情况发生在Thread.Start方法进行的传输过程中, 大多数线程池操作和通过 Windows 消息泵 Windows 窗体线程封送处理。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. 不会在不传输压缩堆栈的不安全线程池操作UnsafeQueueUserWorkItem (如方法) 中发生。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. ExecutionContextCapture提供和CreateCopy方法来获取执行上下文和方法,以设置当前线程的执行上下文。RunThe 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.

ExecutionContext无法在另一个线程上设置与线程关联的。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. 若要将ExecutionContext从一个线程传播到另一个线程, 请创建ExecutionContext的副本。To propagate the ExecutionContext from one thread to another, make a copy of the ExecutionContext.

在内部, ExecutionContext将存储LogicalCallContext与相关联的所有数据。Internally, the ExecutionContext stores all data that is associated with the LogicalCallContext. 这允许LogicalCallContext在复制和传输ExecutionContext时传播数据。This allows the LogicalCallContext data to be propagated when the ExecutionContext is copied and transferred.

方法

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()

释放 ExecutionContext 类的当前实例所使用的所有资源。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)

用重新创建当前执行上下文的实例所需的逻辑上下文信息设置指定的 SerializationInfo 对象。Sets the specified SerializationInfo object with the logical context information needed to recreate an instance of the current execution context.

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

获取当前实例的 TypeGets 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()

创建当前 Object 的浅表副本。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)

适用于