WaitAll for multiple handles on a STA thread is not supported

前端 未结 5 1779
猫巷女王i
猫巷女王i 2020-12-03 00:36
  1. Why do I get this error message? \"WaitAll for multiple handles on a STA thread is not supported.\"
  2. Should I use [MTAThreadAttribute] attribut? Update
5条回答
  •  眼角桃花
    2020-12-03 01:17

    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();
    

提交回复
热议问题