473,569 Members | 2,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_QUERYENDSESS ION 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_QUERYENDSESS ION = 0x11;
int WM_ENDSESSION = 0x16;
if (m.Msg == WM_QUERYENDSESS ION || m.Msg == WM_ENDSESSION)
{
base.WndProc(re f m);
this.Close();
}
else
{
base.WndProc(re f m);
}
}

The MainForm is started in normal state and is set to invisible after start.
PLEASE HELP ME!
Nov 16 '05 #1
4 8801
David,

You need to set the return value when the message is WM_QUERYENDSESS ION.
Basically, your code should look like this:

// Process the message normally.
base.WndProc(re f m);

// If the result is to query to end the session, set the return value to 1.
if (m.Msg == WM_QUERYENDSESS ION)
{
// 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.co m
"David Meier" <Da********@dis cussions.micros oft.com> wrote in message
news:1A******** *************** ***********@mic rosoft.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_QUERYENDSESS ION 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_QUERYENDSESS ION = 0x11;
int WM_ENDSESSION = 0x16;
if (m.Msg == WM_QUERYENDSESS ION || m.Msg == WM_ENDSESSION)
{
base.WndProc(re f m);
this.Close();
}
else
{
base.WndProc(re f 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_QUERYENDSESS ION = 0x11;
int WM_ENDSESSION = 0x16;
// Carry on with the message.
base.WndProc(re f m);
if (m.Msg == WM_QUERYENDSESS ION)
{
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_QUERYENDSESS ION 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_QUERYENDSESS ION.
Basically, your code should look like this:

// Process the message normally.
base.WndProc(re f m);

// If the result is to query to end the session, set the return value to 1.
if (m.Msg == WM_QUERYENDSESS ION)
{
// 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.co m
"David Meier" <Da********@dis cussions.micros oft.com> wrote in message
news:1A******** *************** ***********@mic rosoft.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_QUERYENDSESS ION 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_QUERYENDSESS ION = 0x11;
int WM_ENDSESSION = 0x16;
if (m.Msg == WM_QUERYENDSESS ION || m.Msg == WM_ENDSESSION)
{
base.WndProc(re f m);
this.Close();
}
else
{
base.WndProc(re f 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.Exi t instead to shut down?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"David Meier" <Da********@dis cussions.micros oft.com> wrote in message
news:3D******** *************** ***********@mic rosoft.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_QUERYENDSESS ION = 0x11;
int WM_ENDSESSION = 0x16;
// Carry on with the message.
base.WndProc(re f m);
if (m.Msg == WM_QUERYENDSESS ION)
{
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_QUERYENDSESS ION 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_QUERYENDSESS ION.
Basically, your code should look like this:

// Process the message normally.
base.WndProc(re f m);

// If the result is to query to end the session, set the return value to
1.
if (m.Msg == WM_QUERYENDSESS ION)
{
// 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.co m
"David Meier" <Da********@dis cussions.micros oft.com> wrote in message
news:1A******** *************** ***********@mic rosoft.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_QUERYENDSESS ION 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_QUERYENDSESS ION = 0x11;
> int WM_ENDSESSION = 0x16;
> if (m.Msg == WM_QUERYENDSESS ION || m.Msg == WM_ENDSESSION)
> {
> base.WndProc(re f m);
> this.Close();
> }
> else
> {
> base.WndProc(re f 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.Exi t instead to shut down?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"David Meier" <Da********@dis cussions.micros oft.com> wrote in message
news:3D******** *************** ***********@mic rosoft.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_QUERYENDSESS ION = 0x11;
int WM_ENDSESSION = 0x16;
// Carry on with the message.
base.WndProc(re f m);
if (m.Msg == WM_QUERYENDSESS ION)
{
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_QUERYENDSESS ION 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_QUERYENDSESS ION.
Basically, your code should look like this:

// Process the message normally.
base.WndProc(re f m);

// If the result is to query to end the session, set the return value to
1.
if (m.Msg == WM_QUERYENDSESS ION)
{
// 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.co m
"David Meier" <Da********@dis cussions.micros oft.com> wrote in message
news:1A******** *************** ***********@mic rosoft.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_QUERYENDSESS ION 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_QUERYENDSESS ION = 0x11;
> int WM_ENDSESSION = 0x16;
> if (m.Msg == WM_QUERYENDSESS ION || m.Msg == WM_ENDSESSION)
> {
> base.WndProc(re f m);
> this.Close();
> }
> else
> {
> base.WndProc(re f 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
7112
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 executed, other necessary Windows Services have been terminated before it can actually send the mail. I've updated my...
3
1189
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
3061
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 hanging, like it's in an infinite loop, while returning from constructing an object. Through the debugger, I've found that it is hanging on the returning...
8
4171
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 send mail code is executed, other necessary Windows Services have been terminated before it can actually send the mail. I've updated my...
0
1216
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 void WndProc(ref Message m) { // Exit message code. int WM_QUERYENDSESSION = 0x11;
6
8747
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 talk to the UPS over a special device driver. Through this device driver I can detect that the UPS is going to notify Windows 2000 server to...
2
11391
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, OpenProcessToken, LookupPrivilegeValue, AdjustTokenPrivilegese, ExitWindowsEx. I am trying to avoid using any API calls if possible and to use...
7
4257
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 what about *preventing* that shutdown? (and yes - I know the user can always unplug the machine) Thanks.
3
2289
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 Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing to save the data before the...
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.