title: Is there a better way to wait for queued threads?
body: <p>Is there a better way to wait for queued threads before execute another process?</p>
  
  <p>Currently I'm doing:</p>
  
  <pre><code>this.workerLocker = new object(); // Global variable
  this.RunningWorkers = arrayStrings.Length; // Global variable
  
  // Initiate process
  
  foreach (string someString in arrayStrings)
  {
       ThreadPool.QueueUserWorkItem(this.DoSomething, someString);
       Thread.Sleep(100);
  }
  
  // Waiting execution for all queued threads
  lock (this.workerLocker)  // Global variable (object)
  {
       while (this.RunningWorkers &gt; 0)
       {
            Monitor.Wait(this.workerLocker);
       }
  }
  
  // Do anything else    
  Console.WriteLine("END");
  </code></pre>
  
  <hr>
  
  <pre><code>// Method DoSomething() definition
  public void DoSomething(object data)
  {
      // Do a slow process...
      .
      .
      .
  
      lock (this.workerLocker)
      {
          this.RunningWorkers--;
          Monitor.Pulse(this.workerLocker);
      }
  }
  </code></pre>