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

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

See Also

Reference

ThreadingTools Class

WithCancellation Overload

Microsoft.VisualStudio.Threading Namespace