My program is starting with windows, I have such code to prevent exiting application when user hits exit button:
protected override void OnClosing(CancelEventArgs e)
{
this.ShowInTaskbar = false;
e.Cancel = true;
this.Hide();
}
It is working very well, but when I want to turn off computer, every time I get screen like 'One or more application cannot be exited. Cancel - Exit despite this.
How can I allow windows to normally exit my application, but also prevent user from exiting it when click red exit button?