Best way: to implement an interrupt/cancel feature for all your threaded workers

.net, c#, multithreading

Solution

Use .NET 4.0 `Task`s with `CancellationToken`s - they are the new universal cancellation system.

Problem

So my question is how to implement cancel/interrupt feature into all (I mean ALL) thread workers in your application in best and most elegant way? It's not important if it's an HttpWebRequest, IO operation or calculation. User should have an possibility to cancel every action/thread at any moment.

Original source