It is possible to listen to two cancellation tokens simultaneously in Visual Studio, using the CreateLinkedTokenSource method to join them into one token.
Async tasks can also be chained with a CancellationToken.
Furthermore, a composite cancellation token, consisting of several other tokens, can be used to cancel a task.
This article explains how to listen to two cancellation tokens simultaneously in Visual Studio, so that an operation can be cancelled if either token requests it. The CreateLinkedTokenSource method is used to join two tokens into one token, allowing the token to be passed to methods that take just one cancellation token as an argument. When the linked token throws an OperationCanceledException, the token that is passed to the exception is the linked token, not either of the predecessor tokens.
How to: Listen for Multiple Cancellation Requests | Microsoft Docs
A cancellation token allows the work to be cancelled if it has not yet started. Run(Func<Task>, CancellationToken) Queues the specified work to run on the thread pool and returns a proxy for the task returned by function. A cancellation token allows the work to be cancelled if it has not yet started.
How to chain async tasks with a CancellationToken?
.NET C# developers can cancel a task with a composite cancellation token, which consists of several other tokens. This can be done by creating a composite token in the constructor of the task, and then passing it to the CancellationTokenSource object. If the task is only needed to be cancelled, a shorter loop can be created that will perform the cancellation check and throw the exception in one step.
Cancelling a Task with a composite cancellation token in .NET C# | Exercises in .NET with Andras Nemes
– you can implement your own version of cancellation, at the cost of additional property/variable. Usually this approached is called cancellationToken , and ...
Seva Zaikov - How to Cancel Your Promise
As an optimization, the cancellation signal propagates upwards the promise chain so that an ongoing operation e.g. network request can be aborted. However, not ...
Cancellation | bluebird