473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Windows shutdown hanging - Getting desperate!

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!
Nov 16 '05 #1
4 8781
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]
- mv*@spam.guard.caspershouse.com
"David Meier" <Da********@discussions.microsoft.com> wrote in message
news:1A**********************************@microsof t.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!

Nov 16 '05 #2
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]
- mv*@spam.guard.caspershouse.com
"David Meier" <Da********@discussions.microsoft.com> wrote in message
news:1A**********************************@microsof t.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!


Nov 16 '05 #3
David,

The only other thing that you should be sure to do is set the Result
property of the message to 0 when the message is WM_ENDSESSION. This
indicates that it is ok to shut down.

It ^might^ be an issue that you have the log file open. Does calling
close on the application actually close the app? Can you use
Application.Exit instead to shut down?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"David Meier" <Da********@discussions.microsoft.com> wrote in message
news:3D**********************************@microsof t.com...
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]
- mv*@spam.guard.caspershouse.com
"David Meier" <Da********@discussions.microsoft.com> wrote in message
news:1A**********************************@microsof t.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!


Nov 16 '05 #4
Hi Niclas, you are a mastermind! It seems to work now when putting the
0-return value in the code. I just wonder why other people got it to work
without both of the return values... Thanks a LOT! Dave.

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

The only other thing that you should be sure to do is set the Result
property of the message to 0 when the message is WM_ENDSESSION. This
indicates that it is ok to shut down.

It ^might^ be an issue that you have the log file open. Does calling
close on the application actually close the app? Can you use
Application.Exit instead to shut down?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"David Meier" <Da********@discussions.microsoft.com> wrote in message
news:3D**********************************@microsof t.com...
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]
- mv*@spam.guard.caspershouse.com
"David Meier" <Da********@discussions.microsoft.com> wrote in message
news:1A**********************************@microsof t.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!


Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bill Sonia | last post by:
I'm written a Windows Service to send e-mails on events like OnStart, OnStop, OnShutDown using System.Web.Mail. It works for everything but OnShutdown. My guess is that once my send mail code is...
3
by: Senthil | last post by:
Hi, I would like to know the code for reboot and shutdown windows xp professional using VB.Net. thanx Senthil
8
by: briforge | last post by:
I am writing a program for the Palm OS in c++. I have already posted this to a palm development forum but I'm desperate for a fix, so I hope this cross-post isn't offensive. My program is...
8
by: Bill Sonia | last post by:
I've written a Windows Service to send e-mails on events like OnStart, OnStop, OnShutDown using System.Web.Mail. It works for everything but OnShutdown. My guess is that for OnShutDown, once my...
0
by: David Meier | last post by:
Hi list, I am facing the problem that the system shutdown does not close my .net application running in the system tray. After googeling around I implemented this function: protected override...
6
by: carbon_dragon | last post by:
Ok, so here is the problem. I'm working on a headless server program implemented as a .NET C# Console project. There is a UPS mounted to this server (though not a windows compliant UPS). I can only...
2
by: Brian Worth | last post by:
I have just upgraded from VB 4.0 to VB .NET 2002. One program under VB 4.0 was able to shut down or restart the (windows XP) machine using a series of API calls. (Getlasterror, GetCurrentProcess,...
7
by: Mark | last post by:
It is possible from a .NET application to prevent Windows from shutting down? I understand that a .NET application can "know" that windows is initiating the process of to shutting down - but...
3
by: Chris Knievel | last post by:
Hi, i am trying to save some data in a excel spreadsheet, whenever the programm shuts down. Mostly this happens when a user is logging off or shuts the computer down. im am using the Private Sub...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.