Re: Windows shutdown hanging - Getting desperate!

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: David Meier (DavidMeier_at_discussions.microsoft.com)
Date: 09/23/04


Date: Thu, 23 Sep 2004 07:35:09 -0700

Hi Nicholas,

thanx a lot for your reply. This is an annoying little big problem! I
reworked the WndProc Method to this:

protected override void WndProc(ref Message m)
{
  int WM_QUERYENDSESSION = 0x11;
  int WM_ENDSESSION = 0x16;
  // Carry on with the message.
  base.WndProc(ref m);
  if (m.Msg == WM_QUERYENDSESSION)
  {
    m.Result = (IntPtr) 1;
  }
  else if (m.Msg == WM_ENDSESSION)
  {
    this.Close();
  }
}

However, it does not change anything. The application closes but shutdown
aborts as well. I noticed that the WM_QUERYENDSESSION message never triggers,
only the WM_ENDSESSION does. I am closing the applications log file (not
shown in the code above) before issuing "this.Close()" and therefore I see
what triggers the applications exit. I guess this does not make a difference,
does it?

Dave.

"Nicholas Paldino [.NET/C# MVP]" wrote:

> David,
>
> You need to set the return value when the message is WM_QUERYENDSESSION.
> Basically, your code should look like this:
>
> // Process the message normally.
> base.WndProc(ref m);
>
> // If the result is to query to end the session, set the return value to 1.
> if (m.Msg == WM_QUERYENDSESSION)
> {
> // Return true for the result.
> m.Result = 1;
> }
> else if (m.Msg == WM_ENDSESSION)
> {
> // Close the form.
> this.Close();
> }
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - mvp@spam.guard.caspershouse.com
>
>
> "David Meier" <DavidMeier@discussions.microsoft.com> wrote in message
> news:1A42A7F2-1531-483E-9ECA-406BD9D3B518@microsoft.com...
> >I have an application running in the background, visible only by a notify
> > icon in the system tray. I learned from other posts to catch the
> > WM_QUERYENDSESSION and WM_ENDSESSION messages. Now, when I want to
> > shutdown/restart the computer the application exits but the shutdown
> > process
> > does not continue anymore. Here's what I've done:
> >
> > protected override void WndProc(ref Message m)
> > {
> > // Exit message code.
> > int WM_QUERYENDSESSION = 0x11;
> > int WM_ENDSESSION = 0x16;
> > if (m.Msg == WM_QUERYENDSESSION || m.Msg == WM_ENDSESSION)
> > {
> > base.WndProc(ref m);
> > this.Close();
> > }
> > else
> > {
> > base.WndProc(ref m);
> > }
> > }
> >
> > The MainForm is started in normal state and is set to invisible after
> > start.
> > PLEASE HELP ME!
>
>
>



Relevant Pages

  • Custom List View
    ... const int Column2Left = 30; ... Font font = new Font; ... protected override void OnKeyDown{ ... public int SelectedIndex { ...
    (microsoft.public.pocketpc.developer)
  • Re: Start a process
    ... > public const int WM_SYSCOMMAND = 0x0112; ... > private void InitializeComponent() ... > protected override void Dispose(bool disposing) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Start a process
    ... How is your desktop program being started at first? ... > public const int WM_SYSCOMMAND = 0x0112; ... > private void InitializeComponent() ... > protected override void Dispose(bool disposing) ...
    (microsoft.public.dotnet.languages.csharp)
  • Custom Control drawing transparent pictures
    ... To achieve this i've used the following int the control code: ... private bool m_bOver = false; ... protected override void OnMouseHover ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: trackbar and double values
    ... As you've probably noticed the TrackBar only supports int types. ... protected override void Dispose(bool disposing) ... private void RecalcValue() ... protected override void OnValueChanged ...
    (microsoft.public.dotnet.general)