ThreadingTools.WithCancellation Method (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.
Namespace: Microsoft.VisualStudio.Threading
Assembly: Microsoft.VisualStudio.Threading (in Microsoft.VisualStudio.Threading.dll)
Syntax
'Declaration
<ExtensionAttribute> _
Public Shared Function WithCancellation ( _
task As Task, _
cancellationToken As CancellationToken _
) As Task
public static Task WithCancellation(
this Task task,
CancellationToken cancellationToken
)
[ExtensionAttribute]
public:
static Task^ WithCancellation(
Task^ task,
CancellationToken cancellationToken
)
static member WithCancellation :
task:Task *
cancellationToken:CancellationToken -> Task
public static function WithCancellation(
task : Task,
cancellationToken : CancellationToken
) : Task
Parameters
task
Type: System.Threading.Tasks.TaskThe task to wrap.
cancellationToken
Type: System.Threading.CancellationTokenThe token that can be canceled to break out of the await.
Return Value
Type: System.Threading.Tasks.Task
Returns Task.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type Task. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.