WinForm应用程序阻止机器重启?

时间:2010-09-17 17:42:15

标签: c# winforms restart

我有一个WinForm应用程序,当它打开并且我尝试重新启动计算机时,我的计算机就会挂起并且不会重新启动。我必须关闭WinForm应用程序,然后重新启动,然后我的计算机重新启动。

我该怎么做才能解决这个问题?

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (!BoolShouldThisClose)
        {
            e.Cancel = true;
            this.Visible = false;
        }
    }

2 个答案:

答案 0 :(得分:1)

请务必注意CloseReason,这样您就不会阻止Windows尝试关闭您的表单。像这样:

    protected override void OnFormClosing(FormClosingEventArgs e) {
        if (e.CloseReason == CloseReason.UserClosing) {
            this.Hide();
            e.Cancel = true;
        }
        else base.OnFormClosing(e);
    }

答案 1 :(得分:0)

您是否在应用中生成了线程并且是否正在运行?如果是这样,请确保它们已设置为IsBackground = true。

相关问题