我有一个包含两个表单的项目,我需要在一个新进程中启动form2,我该怎么做?我知道有
Form2 f2 = new Form2();
f2.Show();
this.Hide();
但在这种情况下,这对我不利。我需要从一个新进程开始(作为另一个.exe文件)。
所以我怎么能这样做?
[UPDATE]
我忘了告诉你我需要将一些信息传递给form2,比如
Form2 f2 = new Form2(someInformation);
f2.Show();
this.Hide();
您可以在单独的项目中创建Form2并通过以下方式调用构建的exe文件
System.Diagnostics.Process.Start("Form2.exe");
如果您的意思是新线程,请执行以下操作:
var secondFormThread = new Thread(() => Application.Run(new Form(someInformation)));
this.Hide(); // Hide the current form
secondFormThread .Start(); // now show the other one in a new thread
secondFormThread .WaitForExit(); // wait for this thread to finish or
// maybenot, may add a timeout. Whatever
// suits your needs.
this.Show(); // Show the first form again
创建Form的实例并将其显示在单独的线程中。
new Thread(() => {
Form2 f2 = new Form2(someInformation);
f2.ShowDialog();
}).Start();