Nofity Icon and Windows shutdown/restart

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

Guest

Does anyone know an approach to knowing when your application with a notify
icon is being shut down by windows?

I have an application with a notify icon and a back ground thread. The back
ground thread is a regular System.Threading.Thread with background mode set.
It is not a "back ground worker". When windows is told to restart, and I will
guess shut down, it does not. I was expecting the back ground thread to get a
thread abort exception or the main form to get a formClosing or maybe an
disposed event; but those are not occuring either.

All ideas appreaciated...Chuck
 
So let's refine this -- is there a better option then to override WndProc in
form class and watch for a WM_QUERYENDSESSION message?
 
So let's refine this -- is there a better option then to override WndProc in
form class and watch for a WM_QUERYENDSESSION message?

There's a corresponding event in the SystemEvents class you can
handle.


Mattias
 
As Mattias points out, SystemEvents.SessionEnding is an alternative. The
issue with using this over an override of WndProc is that, as MS doc states,
"there is no deterministic way to decide whether the Closing event will fire
before the SessionEnding event. If order is important to you, you will need
to override WndProc.

What as occuring to me was that I had expected the main form to get a
formClosing event before a child. Bad assumption. My subform was getting it's
formClosing event and cancelling it and that stoped the shut down. So my fix
is to over ride WndProc and set a flag that formClosing checks to see if it
should cancel the close or not.
 
Back
Top