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

前端 未结 4 1055
野的像风
野的像风 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 07:02

    Try this. It runs the new Form on its own thread with its own message queues and what not. Run this code:

    new Thread(new ThreadStart(delegate
    {
       Application.Run(new Form());
    })).Start();
    

    Use Thread.CurrentThread.GetHashCode() to test that is runs on different thread.

提交回复
热议问题