Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Async methods that do not need cancellation

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?

like image 877
UserControl Avatar asked Jul 06 '14 07:07

UserControl


1 Answers

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)
like image 164
ta.speot.is Avatar answered Sep 20 '22 01:09

ta.speot.is