O'Reilly logo

C# Multithreaded and Parallel Programming by Rodney Ringler

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

Canceling a BackgroundWorker thread

Executing a time-consuming process in an independent thread allows us to work concurrently while showing its progress. One of the advantages of doing this is the possibility of allowing the user to go on using the controls in the graphical user interface without the restrictions of single-threaded applications. For example, perhaps he or she wants to cancel the CodeBreaking process instead of letting it finish.

The BackgroundWorker component simplifies the task of canceling the execution of the code running in the thread it creates without a lot of programming effort.

To do this, we must assign the true value to the WorkerSupportsCancellation property of BackgroundWorker. It is a bool value and tells whether the ...

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