Shutdown and SystemTray App...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Thanks in advance...

I have a windows forms c#.NET app that runs in the system tray; I'm
experiencing intermitent problems with when the end-user goes to Log Off,
Shutdown, etc...

For the most part the app always closes on these events but, there are times
when the user has to reselect the Log Off, Shutdown, etc button. It's almost
as if their shutdown process was terminated...

Again, this is an intermitent problem. Below is code I use in the
application to determine when the users session is ending so that way I can
close the app down...

private int _wm_QueryEndSession = 0x11;

protected override void WndProc(ref Message m)
{
try
{
if(m.Msg == this._wm_QueryEndSession)
{
Application.Exit();
}
base.WndProc(ref m);

}
catch(Exception ex)
{
Helper.writeEvent(ex,System.Diagnostics.EventLogEntryType.Error);
}
}

Am I missing something or is there a sure fire way to kill the app and
ensure the user is able to shutdown properly everytime..??

Any help would be great..!
 
Jakob--

This url was of no help; I'm already overriding the WndProc as I showed from
my code example...

Other ideas..?
 
AFAIK, using the SessionEnded event is the "official" way to close down a
system tray application properly (e.g. see this example:
http://msdn.microsoft.com/msdnmag/issues/05/09/WindowsForms/default.aspx).
The last time I wrote a tray application I did not use SessionEnded and I did
not use WM_QUERYENDSESSION. The only thing I did was to catch the
WM_SYSCOMMAND message in order to prevent the user from shutting down the app
from the control menu. The system takes care of closing down my app when the
user logs off and it works fine.

Have you added some code to the Form.Closing event that might break things?

Regards, Jakob.
 
Back
Top