Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question