开发者

WinForm Application Prevents Machine Restart?

I have a WinForm application, 开发者_JAVA百科and when it's open and I try to restart my computer, my computer just hangs and doesn't restart. I have to actually close the WinForm app, and then restart, and my computer restarts.

What can I do to solve this?

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


Be sure to pay attention to the CloseReason so you won't block Windows trying to close your form. Like this:

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


Have you spawned threads in your app and are they running? If so, make sure they're set to IsBackground = true.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜