V
V
Vanes Ri_Lax2015-12-15 12:40:18
C++ / C#
Vanes Ri_Lax, 2015-12-15 12:40:18

Why won't the program let Windows shut down?

Hello, I wrote a program in c #, it hangs in the tray.
When I turn off the computer, Windows displays a message that my application does not allow windows to restart.
What could be the problem and how to fix it?
Thank you very much in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Arxont, 2015-12-15
@vanesxl

It's simple - apparently you rewrote the close function: Close(). And instead of closing the program somewhere there, the program is minimized to the tray, so when the computer is turned off, the program tries to close, and on closing the handler that blocks the closing.
To fix it, you can use the FormClosingEventArgs Class

private void MyForm_FormClosing(object sender, FormClosingEventArgs e)
{
    if (e.CloseReason != CloseReason.WindowsShutDown)
    {
        // Ваш код
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question