我有一些关闭应用程序的代码。但是,如果我在Visual Studio中运行应用程序并进行调试,我想停止调试而不是关闭我的计算机。任何建议:
代码:
#if DEBUG
throw new Exception("Can't shutdown!");
#else
try
{
this.Shutdown();
}
finally
{
Process.Start("shutdown.exe", "-r -f -t 0");
}
#endif
答案 0 :(得分:3)
尝试:
if (Debugger.IsAttached)
throw new Exception("Can't shutdown!");
else
try
{
this.Shutdown();
}
finally
{
Process.Start("shutdown.exe", "-r -f -t 0");
}