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

后端 未结 6 1246
天涯浪人
天涯浪人 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:28

    I bet what you're doing is something like this:

    new Thread(() => new TestForm().Show()).Start();
    

    because this makes the window disappear immediately, like you describe.

    Try this instead:

     new Thread(() => new TestForm().ShowDialog()).Start();
    

    ShowDialog spins its own message pump, and only returns when the window is closed.

提交回复
热议问题