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 - Waiting for the threads' signals

There are more elegant ways to wait for the various concurrent threads to finish their work. The WaitForThreadsToDie procedure is easy to understand, but is not as elegant as expected.

Now, we are going to make some changes to the code in order to use event wait handles instead of using a loop to check for the threads that are alive:

  1. Stay in the project, OldStarsFinder.
  2. Open the code for Program.cs.
  3. Replace the line [STAThread] with the following line (before the Main method declaration):
    [MTAThread]
    
  4. Open the code for the Windows Form, Form1 (frmStarsFinder).
  5. Add the following private variable:
    // The AutoResetEvent instances array
    private AutoResetEvent[] praoAutoResetEventArray;
    
  6. Replace the code in ...

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