One thing that has been notoriously difficult in the world of asynchronous code (among other things, such as other threading and synchronization constructs) is the means to cancel an operation. Starting with .NET 4.0, cancellation has been unified in terms of two concepts:
We don’t elaborate on the intricacies of the mechanism here but instead focus on the essentials of the feature. Figure 30.6 summarizes the basic interactions with constructs for cancellation.
The first key notion is that of a
CancellationTokenSource. This class is where ...