ExecutionContext Classe

Definição

Gerencia o contexto de execução do thread atual.Manages the execution context for the current thread. Essa classe não pode ser herdada.This class cannot be inherited.

public ref class ExecutionContext sealed
public ref class ExecutionContext sealed : IDisposable, System::Runtime::Serialization::ISerializable
public ref class ExecutionContext sealed : System::Runtime::Serialization::ISerializable
public sealed class ExecutionContext
public sealed class ExecutionContext : IDisposable, System.Runtime.Serialization.ISerializable
[System.Serializable]
public sealed class ExecutionContext : System.Runtime.Serialization.ISerializable
[System.Serializable]
public sealed class ExecutionContext : IDisposable, System.Runtime.Serialization.ISerializable
type ExecutionContext = class
type ExecutionContext = class
    interface IDisposable
    interface ISerializable
[<System.Serializable>]
type ExecutionContext = class
    interface ISerializable
[<System.Serializable>]
type ExecutionContext = class
    interface IDisposable
    interface ISerializable
Public NotInheritable Class ExecutionContext
Public NotInheritable Class ExecutionContext
Implements IDisposable, ISerializable
Public NotInheritable Class ExecutionContext
Implements ISerializable
Herança
ExecutionContext
Atributos
Implementações

Comentários

A ExecutionContext classe fornece um único contêiner para todas as informações relevantes para um thread lógico de execução.The ExecutionContext class provides a single container for all information relevant to a logical thread of execution. No .NET Framework, isso inclui contexto de segurança, contexto de chamada e contexto de sincronização.In .NET Framework, this includes security context, call context, and synchronization context. No .NET Core, não há suporte para o contexto de segurança e o contexto de chamada, no entanto, o contexto de representação e a cultura normalmente fluiriam com o contexto de execução.In .NET Core, the security context and call context are not supported, however, the impersonation context and culture would typically flow with the execution context. Também no .NET Core, o contexto de sincronização não flui com o contexto de execução, enquanto em .NET Framework ele pode em alguns casos.Also in .NET Core, the synchronization context does not flow with the execution context, whereas in .NET Framework it may in some cases. Para obter mais informações, consulte ExecutionContext vs SynchronizationContext.For more information, see ExecutionContext vs SynchronizationContext.

A ExecutionContext classe fornece a funcionalidade do código de usuário para capturar e transferir esse contexto em pontos assíncronos definidos pelo usuário.The ExecutionContext class provides the functionality for user code to capture and transfer this context across user-defined asynchronous points. O Common Language Runtime garante que o ExecutionContext seja transferido consistentemente entre pontos assíncronos definidos pelo tempo de execução dentro do processo gerenciado.The common language runtime ensures that the ExecutionContext is consistently transferred across runtime-defined asynchronous points within the managed process.

  • O seguinte é aplicável somente a .NET Framework.The following is applicable to .NET Framework only. -

Um contexto de execução é o equivalente gerenciado de um apartamento COM.An execution context is the managed equivalent of a COM apartment. Dentro de um domínio de aplicativo, o contexto de execução inteiro deve ser transferido sempre que um thread é transferido.Within an application domain, the entire execution context must be transferred whenever a thread is transferred. Essa situação ocorre durante as transferências feitas pelo Thread.Start método, a maioria das operações de pool de threads e Windows Forms o empacotamento de threads por meio da bomba de mensagem do 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. Ele não ocorre em operações de pool de threads não seguros (como o UnsafeQueueUserWorkItem método), que não transferem a pilha compactada.It does not occur in unsafe thread pool operations (such as the UnsafeQueueUserWorkItem method), which do not transfer the compressed stack. Sempre que os fluxos de pilha compactados, a entidade gerenciada, a sincronização, a localidade e o contexto do usuário também fluem.Wherever the compressed stack flows, the managed principal, synchronization, locale, and user context also flow. A ExecutionContext classe fornece os Capture CreateCopy métodos e para obter o contexto de execução e o Run método para definir o contexto de execução para o thread atual.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.

Um ExecutionContext que está associado a um thread não pode ser definido em outro thread.An ExecutionContext that is associated with a thread cannot be set on another thread. Tentar fazer isso resultará em uma exceção sendo gerada.Attempting to do so will result in an exception being thrown. Para propagar o ExecutionContext de um thread para outro, faça uma cópia do ExecutionContext .To propagate the ExecutionContext from one thread to another, make a copy of the ExecutionContext.

Internamente, o ExecutionContext armazena todos os dados associados ao LogicalCallContext .Internally, the ExecutionContext stores all data that is associated with the LogicalCallContext. Isso permite que os LogicalCallContext dados sejam propagados quando o ExecutionContext é copiado e transferido.This allows the LogicalCallContext data to be propagated when the ExecutionContext is copied and transferred.

Métodos

Capture()

Captura o contexto de execução do thread atual.Captures the execution context from the current thread.

CreateCopy()

Cria uma cópia do contexto de execução atual.Creates a copy of the current execution context.

Dispose()

Libera todos os recursos usados pela instância atual da classe ExecutionContext.Releases all resources used by the current instance of the ExecutionContext class.

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object.

(Herdado de Object)
GetHashCode()

Serve como a função de hash padrão.Serves as the default hash function.

(Herdado de Object)
GetObjectData(SerializationInfo, StreamingContext)

Define o objeto SerializationInfo especificado com as informações lógicas do contexto necessárias para recriar uma instância do contexto de execução atual.Sets the specified SerializationInfo object with the logical context information needed to recreate an instance of the current execution context.

GetType()

Obtém o Type da instância atual.Gets the Type of the current instance.

(Herdado de Object)
IsFlowSuppressed()

Indica se o fluxo do contexto de execução está suprimido no momento.Indicates whether the flow of the execution context is currently suppressed.

MemberwiseClone()

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

(Herdado de Object)
Restore(ExecutionContext)

Restaura um contexto de execução capturado no thread atual.Restores a captured execution context on to the current thread.

RestoreFlow()

Restaura o fluxo do contexto de execução em threads assíncronos.Restores the flow of the execution context across asynchronous threads.

Run(ExecutionContext, ContextCallback, Object)

Executa um método em um contexto de execução especificado no thread atual.Runs a method in a specified execution context on the current thread.

SuppressFlow()

Suprime o fluxo do contexto de execução em threads assíncronos.Suppresses the flow of the execution context across asynchronous threads.

ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object.

(Herdado de Object)

Aplica-se a