Cancellation
TAP methods often provide an overload with a CancellationToken parameter that you can use to cancel the ongoing operation. Such an overload only exists if the underlying operation has a meaningful way to abort work. If present, the CancellationToken parameter is passed after the parameters that occur on the corresponding synchronous variant.
For example, if an operation gets asynchronous behavior because it’s processed through a work queue, cancellation can be achieved by deleting the item from the queue if it hasn’t started yet. Another typical example is when the asynchronous operation performs other asynchronous operations which are cancelable. In that case, the CancellationToken is passed down to the underlying operations, providing ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access