如何在c#中重新启动Exe.Project [英] How To Restart Exe.Project in c#
本文介绍了如何在c#中重新启动Exe.Project的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想重启主程序项目exe,我使用这段代码但不行。
i want restart main program project exe, i'm use this code but not work.
form1.close();
form1.show();
推荐答案
您可以使用 Application.Restart() [ ^ ]
另外:
如何重新启动C#WinForm应用程序? [ ^ ]
自行重启应用程序 [ ^ ]
You can use Application.Restart()[^]
Also:
How do I restart my C# WinForm Application?[^]
Restart an application by itself[^]
一个重要的问题这里问的是:为什么你想重新启动应用程序,当你自己的代码关闭(显然)主表单(在WinForm应用程序中)终止应用程序?
为什么要关闭应用程序/表单如果你想让它活着?
为什么不做像写一个EventHandler这样的事情对于主表单的结束事件:并让用户选择退出应用程序,还是继续?
An important question ask here is: Why do you want to restart the Application when it is your own code that closes (evidently) the Main Form which (in a WinForm app) terminates the Application ?
Why close the Application/Form if you want to keep it "alive" ?
Why not do something like write an EventHandler for the Main Form 'Closing Event: and give the user the choice to quit the Application, or keep going ?
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (
MessageBox.Show(
"Quit the Application ?",
"Do you really want to quit ?",
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button2)
== DialogResult.No)
{
e.Cancel = true;
}
}
这篇关于如何在c#中重新启动Exe.Project的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文