WaitAll for multiple handles on a STA thread is not supported WaitAll for multiple handles on a STA thread is not supported multithreading multithreading

WaitAll for multiple handles on a STA thread is not supported


Actually I use the following to replace WaitHandle.WaitAll(doneEvents);

foreach (var e in doneEvents)    e.WaitOne();


What about using the Tasks to do your threading for you.

http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.aspx

var task1 = Task.Factory.StartNew(() => DoSomeWork());var task2 = Task.Factory.StartNew(() => DoSomeWork());var task3 = Task.Factory.StartNew(() => DoSomeWork());Task.WaitAll(task1, task2, task3);


Use one ManualResetEvent and wait on it. Also maintain a TaskCount variable that is set to the number of worker threads you start, use Interlocked.Decrement in the worker thread code as the very last action of the worker and signal the event if the counter reaches zero,e.g.

// other worker actions...if (Interlocked.Decrement(ref taskCount) == 0)   doneEvent.Set();