title: Is there a limit on Background Workers? Technical or Common Sense
body: <p>In Program.cs I have the below method that is checking and the Syncing 5 SQL db's with the central server. Each one is separate from the other so I thought to speed up my program's load time by having them all run at the same time.</p>
  
  <p>Unfortunately it is very flaky working one time then not the next. The local DB is SQLExpress 2005 and the central DB is SQL Server Standard 2005.</p>
  
  <p>Is there a limit on how many connections either of those can have?  How about Background Workers, can I only have so many running at once?  I am sure there is a MUCH more eloquent way of doing this, I'd love to hear(see) them.</p>
  
  <p>This is how I call this in Main() in Program.cs --> </p>
  
  <p><code>if(IsSqlAvailable())
                  SyncNow();</code></p>
  
  <hr>
  
  <pre><code>internal static void SyncNow()
      {
  
  
  
              #region ConnectDB Merge Sync Background Thread
  
              BackgroundWorker connectBW = new BackgroundWorker
                                               {
                                                   WorkerReportsProgress = false,
                                                   WorkerSupportsCancellation = true
                                               };
              connectBW.DoWork += new DoWorkEventHandler(connectBW_DoWork);
              if (connectBW.IsBusy != true)
                  connectBW.RunWorkerAsync();
  
              #endregion
  
              #region aspnetDB Merge Sync Background Thread
  
              BackgroundWorker aspBW = new BackgroundWorker
                                           {
                                               WorkerReportsProgress = false,
                                               WorkerSupportsCancellation = true
                                           };
              aspBW.DoWork += new DoWorkEventHandler(aspBW_DoWork);
              if (aspBW.IsBusy != true)
                  aspBW.RunWorkerAsync();
  
              #endregion
  
              #region MatrixDB Merge Sync Background Thread
  
              BackgroundWorker matrixBW = new BackgroundWorker
                                              {
                                                  WorkerReportsProgress = false,
                                                  WorkerSupportsCancellation = true
                                              };
              matrixBW.DoWork += new DoWorkEventHandler(matrixBW_DoWork);
              if (matrixBW.IsBusy != true)
                  matrixBW.RunWorkerAsync();
  
              #endregion
  
  
  
              #region CMODB Merge Sync Background Thread
  
              BackgroundWorker cmoBW = new BackgroundWorker
                                           {
                                               WorkerReportsProgress = false,
                                               WorkerSupportsCancellation = true
                                           };
              cmoBW.DoWork += new DoWorkEventHandler(cmoBW_DoWork);
              if (cmoBW.IsBusy != true)
                  cmoBW.RunWorkerAsync();
  
              #endregion
  
              #region MemberCenteredPlanDB Merge Sync Background Thread
  
              BackgroundWorker mcpBW = new BackgroundWorker
                                           {
                                               WorkerReportsProgress = false,
                                               WorkerSupportsCancellation = true
                                           };
              mcpBW.DoWork += new DoWorkEventHandler(mcpBW_DoWork);
              if (mcpBW.IsBusy != true)
                  mcpBW.RunWorkerAsync();
  
              #endregion
  
      }
  
      static void mcpBW_DoWork(object sender, DoWorkEventArgs e)
      {
          BackgroundWorker worker = sender as BackgroundWorker;
          try
          {
              MergeRepl mcpMergeRepl = new MergeRepl(SystemInformation.ComputerName + "\\SQLEXPRESS", "WWCSTAGE", "MemberCenteredPlan", "MemberCenteredPlan", "MemberCenteredPlan");
              mcpMergeRepl.RunDataSync();
              areAllInSync += 1; 
          }
          catch (Exception)
          {
              if (worker != null) worker.CancelAsync();
          }
      }
  
      static void cmoBW_DoWork(object sender, DoWorkEventArgs e)
      {
          BackgroundWorker worker = sender as BackgroundWorker;
          try
          {
              MergeRepl cmoMergeRepl = new MergeRepl(SystemInformation.ComputerName + "\\SQLEXPRESS", "WWCSTAGE", "CMO", "CMO", "CMO");
              cmoMergeRepl.RunDataSync();
              areAllInSync += 1; 
          }
          catch (Exception)
          {
              if (worker != null) worker.CancelAsync();
          }
      }
  
      static void connectBW_DoWork(object sender, DoWorkEventArgs e)
      {
          BackgroundWorker worker = sender as BackgroundWorker;
          try
          {
              MergeRepl connectMergeRepl = new MergeRepl(SystemInformation.ComputerName + "\\SQLEXPRESS", "WWCSTAGE", "CONNECT", "Connect", "Connect");
              connectMergeRepl.RunDataSync();
              areAllInSync += 1; 
          }
          catch (Exception)
          {
              if (worker != null) worker.CancelAsync();
          }
      }
  
      static void matrixBW_DoWork(object sender, DoWorkEventArgs e)
      {
          BackgroundWorker worker = sender as BackgroundWorker;
          try
          {
              MergeRepl matrixMergeRepl = new MergeRepl(SystemInformation.ComputerName + "\\SQLEXPRESS", "WWCSTAGE", "MATRIX", "MATRIX", "MATRIX");
              matrixMergeRepl.RunDataSync();
              areAllInSync += 1; 
          }
          catch (Exception)
          {
              if (worker != null) worker.CancelAsync();
          }
      }
  
      static void aspBW_DoWork(object sender, DoWorkEventArgs e)
      {
          BackgroundWorker worker = sender as BackgroundWorker;
          try
          {
              MergeRepl aspnetdbMergeRepl = new MergeRepl(SystemInformation.ComputerName + "\\SQLEXPRESS", "WWCSTAGE", "aspnetdb", "aspnetdb", "aspnetdb");
              aspnetdbMergeRepl.RunDataSync();
              areAllInSync += 1; 
          }
          catch (Exception)
          {
              if (worker != null) worker.CancelAsync();
          }
  
      }
  </code></pre>