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 managed 進程內的執行時間定義非同步點之間一致地傳輸。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 message 抽取 Windows Forms 執行緒封送處理。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. 不會在不會傳輸壓縮堆疊的 unsafe 執行緒集區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. 類別會Capture提供和CreateCopy 方法,以取得執行內容和方法,以設定目前線程的執行內容。Run ExecutionContextThe 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 的淺層複本 (Shallow Copy)。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)

適用於