代码如下:
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//xxxx操作
if (true)
{
Application.Run(new Form1());
}
//xxxx操作
}
}
现在有个问题就是 Application.Run(new Form1()); 会阻塞进程,后面的代码运行不了。也试过用多线程,这样会报错,急死了,求大神帮忙
和阻塞不阻塞没有任何关系。代码总是顺序运行的。写在前面的代码先执行,写在后面的代码后执行。
你可以这么写
var f1 = new Form1();
f1.Load += new EventHandler(a, b) => { xxx操作 });
Application.Run(f1);
机制就是这样的, Application.Run(new Form1()); 后代码就停留在这句代码,如果form关闭了才会往下走,程序就结束了啊
你要弹出窗口后做事情,放在form的load的方法里呗
Run之后就进入Form1了,只有在Form关闭或结束才能只能 new 后面的语句,xx操作写在后面,逻辑有问题。
放到run前面执行,最后一步是run