BackgroundWorker supports two extra features: cancellation and progress. We already looked at cooperative cancellation with the
CancellationToken types, but the
BackgroundWorker defines its own mechanism (it was created long before the latter types were).
In this recipe, we'll take a look at adding cancelation to the primes counting endeavor. Also, in a long running operation it's nice to indicate to the user how things are progressing. The
BackgroundWorker has good support for that, too.
We'll continue with the
CH11.AsyncCalcWithBackgroundWorker project. Alternatively, you can make a copy of it and work on that.
We'll add a Cancel ...