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 - Providing feedback to the UI using a producer-consumer scheme

Now, we are going to make some changes to the application to provide a more responsive UI running the parallelized loop with an asynchronous execution to unblock the UI thread:

  1. Stay in the project, BlobCounter.
  2. Open the code for the Windows Form Form1 (frmNebulaFinder).
  3. Open the Click event in the button butRunBatch and add the following line of code:
    // Start the BackgroundWorker (the consumer)
    bakDisplayImages.RunWorkerAsync();
    

    After the line praoNebulaFinders = new ConcurrentQueue<NebulaFinder>(); (we want the BackgroundWorker to run concurrently with the parallelized loop).

  4. Enclose the trycatch block including the Parallel.ForEach block of code with the following (we ...

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