How can I create WPF controls in a background thread?

后端 未结 8 610
终归单人心
终归单人心 2021-01-17 15:49

I have method which create background thread to make some action. In this background thread I create object. But this object while creating in runtime give me an exception :

8条回答
  •  心在旅途
    2021-01-17 16:26

    See the answer on this question: How to run something in the STA thread?

    When you define your thread, set the ApartmentState to STA:

    thread.SetApartmentState(ApartmentState.STA);
    

    This should do the trick!

提交回复
热议问题