Creating a WPF element in another Thread

后端 未结 2 1110
说谎
说谎 2021-01-22 01:14

I\'m able to run 2 or more WPF windows on different thread. The problem is that now my application in splitted in many windows.

What I really want is have a main window

2条回答
  •  -上瘾入骨i
    2021-01-22 01:49

    It's not possible in WPF and even if it was it would have been a bad idea:

    1. It's not possible in WPF because WPF element can only be used by the thread that created them, if you add a child element from another thread they wouldn't be able to communicate.

    2. In pure Win32 it is possible - but it joins the two threads message queues so the threads are no longer independent (so even if you find a hack that makes it work with WPF it still doesn't help you)

    3. Any thread that has UI and performs a long running task can hung the entire system - so it's impotent to never perform any long running task in a UI thread - instead run the long task in a background thread

    4. because you have to keep the UI thread responsive -> it should never be busy for a noticeable length of time -> it can handle all your windows because it's not too busy.

提交回复
热议问题