Udostępnij za pośrednictwem


ThreadingTools.WithCancellation Method

Definition

Overloads

WithCancellation(Task, CancellationToken)

Wraps a task with one that will complete as cancelled based on a cancellation token, allowing someone to await a task but be able to break out early by cancelling the token.

WithCancellation<T>(Task<T>, CancellationToken)

Wraps a task with one that will complete as cancelled based on a cancellation token, allowing someone to await a task but be able to break out early by cancelling the token.

WithCancellation(Task, CancellationToken)

Wraps a task with one that will complete as cancelled based on a cancellation token, allowing someone to await a task but be able to break out early by cancelling the token.

public:
[System::Runtime::CompilerServices::Extension]
 static System::Threading::Tasks::Task ^ WithCancellation(System::Threading::Tasks::Task ^ task, System::Threading::CancellationToken cancellationToken);
public static System.Threading.Tasks.Task WithCancellation (this System.Threading.Tasks.Task task, System.Threading.CancellationToken cancellationToken);
static member WithCancellation : System.Threading.Tasks.Task * System.Threading.CancellationToken -> System.Threading.Tasks.Task
<Extension()>
Public Function WithCancellation (task As Task, cancellationToken As CancellationToken) As Task

Parameters

task
Task

The task to wrap.

cancellationToken
CancellationToken

The token that can be canceled to break out of the await.

Returns

The wrapping task.

Applies to

WithCancellation<T>(Task<T>, CancellationToken)

Wraps a task with one that will complete as cancelled based on a cancellation token, allowing someone to await a task but be able to break out early by cancelling the token.

public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
 static System::Threading::Tasks::Task<T> ^ WithCancellation(System::Threading::Tasks::Task<T> ^ task, System::Threading::CancellationToken cancellationToken);
public static System.Threading.Tasks.Task<T> WithCancellation<T> (this System.Threading.Tasks.Task<T> task, System.Threading.CancellationToken cancellationToken);
static member WithCancellation : System.Threading.Tasks.Task<'T> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'T>
<Extension()>
Public Function WithCancellation(Of T) (task As Task(Of T), cancellationToken As CancellationToken) As Task(Of T)

Type Parameters

T

The type of value returned by the task.

Parameters

task
Task<T>

The task to wrap.

cancellationToken
CancellationToken

The token that can be canceled to break out of the await.

Returns

Task<T>

The wrapping task.

Applies to