O'Reilly logo

C# 2008 and 2005 Threaded Programming: Beginner's Guide by Gastón C. Hillar

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

Time for action - Using a BackgroundWorker to detect a job completed

You must know the exact code because if you fail just one login process, you will be jailed for the rest of your life. But you want to go on learning parallel programming, therefore, let's enhance our application.

We are going to make some changes to our example to detect when the job running in the independent thread was completed without cancellation, using the features provided by the BackgroundWorker component:

  1. Open the project CodeBreakerApplication.
  2. Open the RunWorkerCompleted event in the BackgroundWorker bakCodebreaker, and enter the following code:
    if (!e.Cancelled) { // Only when the thread was not cancelled // Only when the thread completed its loop // Show a message ...

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