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 - Adding useful classic coordination methods

Now that we have a ParallelAlgorithm class, we can add methods with the well-known techniques we've used so far, and can use them as needed in our applications. Remember that the class must offer us everything we know (up to this chapter) is needed for an efficiently parallelized algorithm:

  1. Stay in the project, OldStarsFinder.
  2. Add the following public static method to force a garbage collection:
    public static void ForceGarbageCollection()
    {
    GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
    }
    
  3. Add the following public method to run the multiple created threads in a synchronous execution:
    public void RunInParallelSync()
    {
    StartThreadsAsync();
    WaitForMyThreadsToDie();
    }
    
  4. Add the following ...

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