How can a new Form be run on a different thread in C#?

前端 未结 4 1022
野的像风
野的像风 2021-01-01 06:27

I\'m just trying to run a new thread each time a button click even occurs which should create a new form. I tried this in the button click event in the MainForm:



        
4条回答
  •  轮回少年
    2021-01-01 06:38

    It's possible to run different forms on different threads. There are two caveats I'm aware of:

    1. Neither form may be an MDI client of the other. Attempting to make a form an MDI client of another when the forms have different threads will fail.
    2. If an object will be sending events to multiple forms and all forms use the same thread, it's possible to synchronize the events to the main thread before raising it. Otherwise, the event must be raised asynchronously and each form must perform its own synchronization mechanism for incoming events.

    Obviously it's desirable not to have any window's UI thread get blocked, but using separate threads for separate windows may be a nice alternative.

提交回复
热议问题