Spawn a new thread to open a new window and close it from a different thread

后端 未结 6 1241
天涯浪人
天涯浪人 2020-12-01 03:57

Right now I have C# code to spawn a new window in a different thread, this works, but as soon as the new spawned window opens, it closes and the thread ends. How would I mak

6条回答
  •  情深已故
    2020-12-01 04:38

    How did you create the new window from the second thread? And what does the thread do after the window is created?

    Without seeing the code, I would guess that the problem is that your second thread does not pump messages on the Windows message queue.

    Are you calling Application.Run on your second thread?

    BTW: note that your design has some limitations. The first thread won't be able to directly control the second window. Whenever you would try to manipulate any UI element on the second window from the first thread, you will have to use Control.Invoke to ensure that the actual UI manipulation occurs on the correct thread.

提交回复
热议问题