WaitAll for multiple handles on a STA thread is not supported

前端 未结 5 1803
猫巷女王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:30

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

提交回复
热议问题