Toptal
Sometimes canceling is a good thing. In many of my .NET projects, I have had plenty of motivation to cancel both internal and external processes. Microsoft learned that developers were approaching this common use case in a variety of complex implementations and decided there must be a better way. Thus, a common cancellation communication pattern was introduced as CancellationToken, which was built using lower-level multithreading and interprocess communication constructs. As part of my initial research into this pattern—and after having dug through the actual .NET source code for Microsoft’s implementation—I found that CancellationToken can solve a much broader set of problems: subscriptions on applications’ run states, timing out operations using different triggers, and general interprocess communications via flags.
The Intended CancellationToken Use Case
CancellationToken was introduced in .NET 4 as a means to enhance and standardize the existing solutions for canceling operations. There are four general approaches to handling cancellation
To read the full article click on the 'post' link at the top.