Szerkesztés

Megosztás a következőn keresztül:


ControlledExecution.Run(Action, CancellationToken) Method

Definition

Caution

ControlledExecution.Run method may corrupt the process and should not be used in production code.

Runs code that can be aborted asynchronously.

public:
 static void Run(Action ^ action, System::Threading::CancellationToken cancellationToken);
[System.Obsolete("ControlledExecution.Run method may corrupt the process and should not be used in production code.", DiagnosticId="SYSLIB0046", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public static void Run (Action action, System.Threading.CancellationToken cancellationToken);
[<System.Obsolete("ControlledExecution.Run method may corrupt the process and should not be used in production code.", DiagnosticId="SYSLIB0046", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
static member Run : Action * System.Threading.CancellationToken -> unit
Public Shared Sub Run (action As Action, cancellationToken As CancellationToken)

Parameters

action
Action

The delegate that represents the code to execute.

cancellationToken
CancellationToken

The cancellation token that can be used to abort execution.

Attributes

Exceptions

The method is not supported on this platform.

The action argument is null.

The current thread is already running the Run(Action, CancellationToken) method.

The execution was aborted.

Remarks

This method enables aborting arbitrary managed code in a non-cooperative manner by throwing an exception in the thread executing that code. While the exception may be caught by the code, it is re-thrown at the end of catch blocks until the execution flow returns to the ControlledExecution.Run method.

Execution of the code is not guaranteed to abort immediately, or at all. This situation can occur, for example, if a thread is stuck executing unmanaged code or the catch and finally blocks that are called as part of the abort procedure, thereby indefinitely delaying the abort. Furthermore, execution may not be aborted immediately if the thread is currently executing a catch or finally block.

Aborting code at an unexpected location may corrupt the state of data structures in the process and lead to unpredictable results. For that reason, this method should not be used in production code and calling it produces a compile-time warning.

Applies to