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 apartment。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 Forms 執行緒封送處理 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. ExecutionContext類別會提供CaptureCreateCopy方法,以取得執行內容和Run方法來設定目前執行緒的執行內容。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.

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到另一個執行緒,從建立一份ExecutionContextTo propagate the ExecutionContext from one thread to another, make a copy of the ExecutionContext.

就內部而言,ExecutionContext將相關聯的所有資料都儲存LogicalCallContextInternally, 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)

適用於