Application not closing when reboot wanted

  • Thread starter Thread starter cybertof
  • Start date Start date
C

cybertof

Hello,

Is there a special message a c# tray application should handle to allow
the system to shutdown/reboot properly ?

Actually when my tray application is launched, the system will not
reboot/shutdown until i close manually the application and try again.


Any hint would be appreciated.


Regards,
Cybertof.
 
Hello,

Is there a special message a c# tray application should handle to allow
the system to shutdown/reboot properly ?

You should handle WM_QUERYENDSESSION. Place the following code in the form
that contains the tray icon component:

private const Int32 WM_QUERYENDSESSION = 0x0011;

protected override void WndProc(ref Message m)
{
if (m.Msg == WM_QUERYENDSESSION)
{
m.Result = (IntPtr)1;
return;
}

base.WndProc(ref m);
}

this will signal to Windows that your program thinks it's ok to be shut
down in response to a windows shutdown.

Additionally, you might want to handle the message WM_ENDSESSION which has
a value of 0x0016, and close your program in response to it.

Hope this helps.
 

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

Back
Top