Async methods that do not need cancellation
.net, async-await, asynchronous, task-parallel-library
Solution
What is fundamental difference between asynchronous operations that expose CancellationToken in their signatures and ones that don't?
Asynchronous operations that expose CancellationToken in their signatures:
- Can be cancelled
Asynchronous operations that don't expose CancellationToken in their signatures:
- Can't be cancelled; or
- they're cancellable some other way (e.g. `yourAsyncObject.Dispose` wraps up everything nicely)
Problem
Learning cancellation of async tasks found this article: As part of supporting the task-based async programming model in the .NET Framework 4.5, we added the `CancellationToken` structure to the signatures of a large set of async APIs in the .NET Framework. For example, the `HttpClient` class exposes a `GetAsync` method overload that accepts a cancellation token. However, it is not essential for all async methods to support cancellation. For instance, if you look at the `HttpContent` class, the `LoadIntoBufferAsync` method does not expose an overload with a cancellation token. What is fundamental difference between asynchronous operations that expose `CancellationToken` in their signatures and ones that don't?