我有一个WinForm应用程序,当它打开并且我尝试重新启动计算机时,我的计算机就会挂起并且不会重新启动。我必须关闭WinForm应用程序,然后重新启动,然后我的计算机重新启动。
我该怎么做才能解决这个问题?
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (!BoolShouldThisClose)
{
e.Cancel = true;
this.Visible = false;
}
}
答案 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。