title: BackgroundWorker limitation on Windows server 2003
body: <p>I am currently having an issue with <code>BackgroundWorker</code> running on Windows Server 2003. I have a window application that need to run more than 50 <code>threads</code>.</p>
  
  <p>The code I wrote use <code>BackgroundWorker</code>(BW) as a Thread wrapper to update data onto a window form. The issue is that the code are able to run more than 50 BWs on my XP machine, but stop at 50 when running on Windows 2003 server.</p>
  
  <p>At first I though there are some kind of limit on the number of thread per app can run. Googling the issue shows that is not the case. I wrote the following code to confirm that.</p>
  
  <pre><code>static int count = 0;
  
  static void Main(string[] args)
  {
      int max = 55; // default value
  
      if (args.Length &gt; 0)
              // use command line parameter if provided
          max = Convert.ToInt32(args[0]); 
  
      List&lt;Thread&gt; threadList = new List&lt;Thread&gt;();
      try
      {
          while (count &lt; max)
          {
              Thread newThread = new Thread(
                          new ParameterizedThreadStart(DummyCall), 1024);
              newThread.Start(count);
  
              threadList.Add(newThread);
              count++;
          }
      }
      catch (Exception ex)
      {
          Console.WriteLine(ex.ToString());
      }
  
      Console.ReadLine();
  }
  
  static void DummyCall(object obj)
  {
      Console.WriteLine(obj.ToString());
      Thread.Sleep(1000000000);
  }
  </code></pre>
  
  <p>The result show as expected. I can see a list of number from 0 to 54 on both my XP machine and the 2003 server.</p>
  
  <p>However, when I try using the BW instead, my XP machine run to 54 and the 2003 server run to 49 (50 BWs). Here is the code.</p>
  
  <pre><code>static int count = 0;
  
  static void Main(string[] args)
  {
      int max = 55; // default value
  
      if (args.Length &gt; 0)
              // use command line parameter if provided
          max = Convert.ToInt32(args[0]); 
  
      List&lt;BackgroundWorker&gt; list = new List&lt;BackgroundWorker&gt;();
  
      try
      {
          while (count &lt; max)
          {
              BackgroundWorker worker = new BackgroundWorker();
              worker.DoWork += new DoWorkEventHandler(worker_DoWork);
              worker.RunWorkerAsync(count);
  
              list.Add(worker);
  
              count++;
          }
      }
      catch (Exception ex)
      {
          Console.WriteLine(ex.ToString());
      }
  
      Console.ReadLine();
  }
  
  static void worker_DoWork(object sender, DoWorkEventArgs e)
  {
      Console.WriteLine(e.Argument.ToString());
      Thread.Sleep(1000000000);
  }
  </code></pre>
  
  <p>So, the question is that why there is a limit on number of BW instances can run on the 2003 server but not XP? Is there anyway I can increase the number of BW instances on 2003 server? If yes, how can I do that?</p>