O'Reilly logo

Windows Presentation Foundation 4.5 Cookbook by Pavel Yosifovich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding cancellation and progress with BackgroundWorker

The BackgroundWorker supports two extra features: cancellation and progress. We already looked at cooperative cancellation with the CancellationTokenSource and 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.

Getting ready

We'll continue with the CH11.AsyncCalcWithBackgroundWorker project. Alternatively, you can make a copy of it and work on that.

How to do it...

We'll add a Cancel ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required