Вот такой код падает с "WaitAll for multiple handles on a STA thread is not supported." на WaitHandle.WaitAll(resetEvents);, как бы обойти эту ошибку?
public void Process(List<string> inputData, Func<string, List<string>> processDelegate)
{
resetEvents = new ManualResetEvent[inputData.Count];
for (int i = 0; i < inputData.Count; i++)
{
int j = i;
resetEvents[i] = new ManualResetEvent(false);
ThreadPool.QueueUserWorkItem(delegate(object o)
{
DoWork(processDelegate, inputData[j]);
resetEvents[(int)o].Set();
}, (object)j);
}
WaitHandle.WaitAll(resetEvents);
OnAllTasksCompleted();
}