title: Mono's BackgroundWorker not working in background?
body: <p>I have a predicament with Mono. I'm trying to understand how or why <code>BackgroundWorker</code> instances don't run concurrently, or at least do not do so very efficiently or quickly. It's almost as if the number of threads is being limited somehow, but I'm not much of a Mono developer or .NET developer, so I throw myself on the mercy of my SO brethren.</p>
  
  <p>Consider the following example:</p>
  
  <pre><code>using System;
  using System.ComponentModel;
  using System.Threading;
  
  namespace backgroundworkertest
  {
    class MainClass
    {
      public static void foo(object sender, DoWorkEventArgs e) {
        Console.WriteLine("Start");
        Thread.Sleep(500);
        Console.WriteLine("Done");
      }
  
      public static void Main (string[] args)
      {
        for(int i = 0; i &lt; 6; i++) {
          BackgroundWorker b = new BackgroundWorker();
          b.WorkerReportsProgress = false;
          b.DoWork += new DoWorkEventHandler(foo);
          b.RunWorkerAsync();
        }
  
        Thread.Sleep(2000);
        Console.WriteLine("Really done");
      }
    }
  }
  </code></pre>
  
  <p>When I run the above, I get the following output.</p>
  
  <pre>
  Start
  Start
  Done
  Start
  Start
  Done
  Start
  Done
  Really Done
  </pre>
  
  <p>First of all, not all of the <code>BackgroundWorker</code>s complete within two whole seconds. From the loop, it's clear I'm instantiating 6 workers, but only 3 print "Done". I feel like two seconds should be long enough for these workers to complete if all 6 were running concurrently.</p>
  
  <p>The real inside story is that I have an app that runs just fine (using a significant number of <code>BackgroundWorker</code>s that fetch images via HTTP in the background. However, the difference is that this app is implemented in C# .NET. When I port the app to Mono, the <code>BackgroundWorker</code>s only seem to be running a couple at a time, and the HTTP connections are prone to timing out as a result. I wanted to see if this was the case, hence the example above and the question...</p>
  
  <p>What's going on here? Why aren't all of the <code>BackgroundWorker</code>s running concurrently? Is there some parameter I need to set?</p>