Enable cancellation
Another important topic is to enable the cancellation of asynchronous operations. If we take a look at the service layer that we implemented in Chapter 8, and Chapter 9, we can see that in some cases we have the possibility of passing CancellationToken as a parameter. The CancellationToken provides a light way to notify all asynchronous operations that the consumer wants to cancel the current transaction. Moreover, our code can examine the CancellationToken.IsCancellationRequested property to detect whether the consumer has requested the cancellation of the task. This kind of approach is especial suitable for long-running operations because the consumer of our asynchronous code can request the cancellation of the current ...
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