检测并重新启动我的坠毁.NET应用程序 [英] Detecting and restarting my crashed .NET application
本文介绍了检测并重新启动我的坠毁.NET应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检测我的.net应用程序崩溃,然后重新启动?
How can I detect that my .NET application has crashed, and then restart it?
推荐答案
另一种解决方案(基于的这个例子)是创建控制应用程序启动器:
Another solution (based on this example) is to create a launcher that controls the application:
class LauncherProgram
{
static int count = 3;
static void Main()
{
Launch();
Thread.Sleep(Timeout.Infinite);
}
static void Launch()
{
Process process = new Process();
process.StartInfo.FileName = "MyApp.exe";
process.EnableRaisingEvents = true;
process.Exited += LaunchIfCrashed;
}
static void LaunchIfCrashed(object o, EventArgs e)
{
Process process = (Process) o;
if (process.ExitCode != 0)
{
if (count-- > 0) // restart at max count times
Launch();
else
Environment.Exit(process.ExitCode);
}
else
{
Environment.Exit(0);
}
}
这篇关于检测并重新启动我的坠毁.NET应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文