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

Using the BackgroundWorker component

The asynchronous operation we used in the previous examples used the thread pool explicitly to do the long running work on another thread. Updating the UI required marshaling code to the UI thread from another thread, to keep the rule of updating the UI from the UI thread intact. All this required some manually managed code.

An alternative is using the BackgroundWorker class that provides automatic management and marshaling for the purpose of performing a long running operation on a background thread.

In this recipe, we'll use the BackgroundWorker to do asynchronous operations without blocking the UI thread and understand its pros and cons.

Getting ready

We'll duplicate most of the UI from the CH11.AsyncCalc

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