title: WaitAll for multiple handles on a STA thread is not supported
body: <ol>
  <li>Why do I get this error message? "WaitAll for multiple handles on a STA thread is not supported."</li>
  <li>Should I use [MTAThreadAttribute] attribut? <strong>Update:</strong> Dosn't work with WPF applications!</li>
  </ol>
  
  <p>Note:
   It error is at line WaitHandle.WaitAll(doneEvents);
   I'm using a standard <strong>WPF project</strong>.</p>
  
  <pre><code>private void Search()
  {
      const int CPUs = 2;
      var doneEvents = new ManualResetEvent[CPUs];
  
      // Configure and launch threads using ThreadPool:
      for (int i = 0; i &lt; CPUs; i++)
      {
          doneEvents[i] = new ManualResetEvent(false);
          var f = new Indexer(Paths[i], doneEvents[i]);
          ThreadPool.QueueUserWorkItem(f.WaitCallBack, i);
      }
  
      // Wait for all threads in pool 
      WaitHandle.WaitAll(doneEvents);
      Debug.WriteLine("Search completed!");
  }
  </code></pre>
  
  <p><strong>Update:</strong> The following solution doesn’t work for WPF applications!
  It is not possible to change the main application attribute to MTAThreadAttribute. It will result in the following error:</p>
  
  <p><strong>Error:</strong> "WaitAll for multiple handles on a STA thread is not supported."</p>