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 - Defining the work to be done in a new thread

A loop like the one used in the aforementioned example is an ideal task to run in an independent thread. That way, we could keep control over the UI and have the possibility of cancelling the job, displaying its progress, hiding the Codebreaker controls, and displaying our fishes game. Hence, we can avoid being shot by the guard (death or jail).

Now, we are going to make some changes to the application, and we will process that loop using a BackgroundWorker in order to run the code in an independent thread:

  1. Open the project, CodeBreakerApplication.
  2. Add a BackgroundWorker component to frmMain (bakCodebreaker).
  3. Open the DoWork event in the BackgroundWorker bakCodeBreaker, and paste the same ...

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