Can't Shutdown with System Tray Application Running

K

Karunakararao

hi all

Can't Shutdown with System Tray Application Running in C#.net

Regards
Venu
 
M

Morten Wennevik

Hi Venu,

I managed that feature once, by cancelling all closing events (user had to select exit from menu). One way to overcome this is to detect the WM_QUERYENDSESSION message from windows

private bool closing = false;

protected override void WndProc(ref Message m)
{
if(m.Msg==0x0011) //WM_QUERYENDSESSION
{
closing = true;
}
base.WndProc(ref m);
}

private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if(!closing) // not ready to close yet
{
this.Hide(); // hide the window instead of closing it
e.Cancel = true;
}
}


Happy coding!
Morten Wennevik [C# MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top