ThreadingTools::WithCancellation<T> Method (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.

Namespace:   Microsoft.VisualStudio.Threading
Assembly:  Microsoft.VisualStudio.Threading (in Microsoft.VisualStudio.Threading.dll)

public:
generic<typename T>
[ExtensionAttribute]
static Task<T>^ WithCancellation(
	Task<T>^ task,
	CancellationToken cancellationToken
)

Parameters

task
Type: System.Threading.Tasks::Task<T>^

The task to wrap.

cancellationToken
Type: System.Threading::CancellationToken

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

Return Value

Type: System.Threading.Tasks::Task<T>^

Returns Task<TResult>.

Type Parameters

T

The type of value returned by the task.

Return to top
Show: