我尝试在新线程中启动表单(请参阅下面的代码架构)。 但是表单在显示后关闭。
Thread te;
dia di = new dia();
private static Thread te;
public static event AddingNewEventHandler tempchange;
public delegate void AddingNewEventHandler(int sender, EventArgs e);
static void Main(string[] args)
{
di.Coneig += new Config.AddingNewEventHandler(config);
te = new Thread(new ThreadStart(di.Show));
te.Start();
while(true)
{
//async code to Form
}
}
public static void config(int[] sender, EventArgs e)
{
//Edit some values in the main(Class variables)
}
最佳答案
Thread te;
dia di = new dia();
static void Main(string[] args)
{
te = new Thread(new ThreadStart(di.Show));
te.Start();
Console.ReadKey();
}
编辑:
这个作品我检查过..
static void Main(string[] args)
{
Form di = new Form();
Thread te = new Thread(() =>
{
Application.EnableVisualStyles();
Application.Run(di);
});
te.Start();
}
关于c# - 在新线程中启动表单并在它们之间引发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33952777/