【发布时间】:2015-02-27 13:42:07
【问题描述】:
我的程序有一个FormClosing 方法来询问用户是否要在关闭表单之前退出程序。这很好用,但我不希望在程序因系统关闭/注销而关闭时显示对话框。如何检测到 kill 命令是由系统发送的,而不是由用户单击表单的 x 发送的? Envrionment.HasShutdownStarted 不起作用。
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Need to check for system shutdown here before the next if is activated
if (MessageBox.Show(...) == DialogResult.No)
{
e.Cancel = true;
this.Activate();
}
}
【问题讨论】: