473,373 Members | 1,676 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,373 software developers and data experts.

Windows won't shut down

Running XP pro, SP2. Visual studio .NET 2003. App written in C#

I have written an application that hides itself when run and shows a
notification icon in the system tray.
If the main form is visible/restored to the desktop, and I tell windows to
restart, windows shuts down fine.
If the main form is minimized to the tray and I tell windows to restart,
other desktop apps close down fine but my program's icon remains sat in the
system tray, windows doesn't close down and there's no error messages.
In normal use, I only allow the app to close down from a right button mouse
activated menu when the app sits in the task bar.

The code for the Closing event is as follows. The menu "close application"
click changes the DialogResult from None to Cancel.
I tested and found that the Closing event is being called in both cases and
,afaik, the result should be ignored anyway as Windows OS is being closed
down.
private void frmOptions_Closing(object sender,
System.ComponentModel.CancelEventArgs e)

{

if (DialogResult == DialogResult.None)

{

e.Cancel = true;

WindowState = FormWindowState.Minimized;

}
}
Nov 16 '05 #1
4 5822
Claire,

I don't think that is the case. When windows is shutting down, if your
app cancels the request to shut down, then it will halt the shutdown.

I think that you should override the WndProc method of your form, and
then handle the WM_QUERYENDSESSION and WM_ENDSESSION messages yourself,
indicating that it is ok to shut down when you get them. I think that the
cancel request from your Closing event handler is being channeled back in
response to these messages.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Claire" <as*******@ntlworld.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Running XP pro, SP2. Visual studio .NET 2003. App written in C#

I have written an application that hides itself when run and shows a
notification icon in the system tray.
If the main form is visible/restored to the desktop, and I tell windows to
restart, windows shuts down fine.
If the main form is minimized to the tray and I tell windows to restart,
other desktop apps close down fine but my program's icon remains sat in
the
system tray, windows doesn't close down and there's no error messages.
In normal use, I only allow the app to close down from a right button
mouse
activated menu when the app sits in the task bar.

The code for the Closing event is as follows. The menu "close application"
click changes the DialogResult from None to Cancel.
I tested and found that the Closing event is being called in both cases
and
,afaik, the result should be ignored anyway as Windows OS is being closed
down.
private void frmOptions_Closing(object sender,
System.ComponentModel.CancelEventArgs e)

{

if (DialogResult == DialogResult.None)

{

e.Cancel = true;

WindowState = FormWindowState.Minimized;

}
}

Nov 16 '05 #2
Hi Nicholas:

I have a similar issue that Claire has. But I have no idea how to implement
WndProc.

Can you show me how to implement WndProc ?

Thanks

David Kao

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

I don't think that is the case. When windows is shutting down, if your
app cancels the request to shut down, then it will halt the shutdown.

I think that you should override the WndProc method of your form, and
then handle the WM_QUERYENDSESSION and WM_ENDSESSION messages yourself,
indicating that it is ok to shut down when you get them. I think that the
cancel request from your Closing event handler is being channeled back in
response to these messages.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Claire" <as*******@ntlworld.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Running XP pro, SP2. Visual studio .NET 2003. App written in C#

I have written an application that hides itself when run and shows a
notification icon in the system tray.
If the main form is visible/restored to the desktop, and I tell windows to
restart, windows shuts down fine.
If the main form is minimized to the tray and I tell windows to restart,
other desktop apps close down fine but my program's icon remains sat in
the
system tray, windows doesn't close down and there's no error messages.
In normal use, I only allow the app to close down from a right button
mouse
activated menu when the app sits in the task bar.

The code for the Closing event is as follows. The menu "close application"
click changes the DialogResult from None to Cancel.
I tested and found that the Closing event is being called in both cases
and
,afaik, the result should be ignored anyway as Windows OS is being closed
down.
private void frmOptions_Closing(object sender,
System.ComponentModel.CancelEventArgs e)

{

if (DialogResult == DialogResult.None)

{

e.Cancel = true;

WindowState = FormWindowState.Minimized;

}
}


Nov 16 '05 #3
David,

It's just an override on your main form:

protected override void WndProc(ref Message m)
{
// Perform pre-processing here.

// Call the base.
base.WndProc(ref m);

// Post-processing here.
}

What you do for the pre or post processing is up to you.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"da*******@opco.com" <da*************@discussions.microsoft.com> wrote in
message news:DF**********************************@microsof t.com...
Hi Nicholas:

I have a similar issue that Claire has. But I have no idea how to
implement
WndProc.

Can you show me how to implement WndProc ?

Thanks

David Kao

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

I don't think that is the case. When windows is shutting down, if
your
app cancels the request to shut down, then it will halt the shutdown.

I think that you should override the WndProc method of your form, and
then handle the WM_QUERYENDSESSION and WM_ENDSESSION messages yourself,
indicating that it is ok to shut down when you get them. I think that
the
cancel request from your Closing event handler is being channeled back in
response to these messages.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Claire" <as*******@ntlworld.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> Running XP pro, SP2. Visual studio .NET 2003. App written in C#
>
> I have written an application that hides itself when run and shows a
> notification icon in the system tray.
> If the main form is visible/restored to the desktop, and I tell windows
> to
> restart, windows shuts down fine.
> If the main form is minimized to the tray and I tell windows to
> restart,
> other desktop apps close down fine but my program's icon remains sat in
> the
> system tray, windows doesn't close down and there's no error messages.
> In normal use, I only allow the app to close down from a right button
> mouse
> activated menu when the app sits in the task bar.
>
> The code for the Closing event is as follows. The menu "close
> application"
> click changes the DialogResult from None to Cancel.
> I tested and found that the Closing event is being called in both cases
> and
> ,afaik, the result should be ignored anyway as Windows OS is being
> closed
> down.
> private void frmOptions_Closing(object sender,
> System.ComponentModel.CancelEventArgs e)
>
> {
>
> if (DialogResult == DialogResult.None)
>
> {
>
> e.Cancel = true;
>
> WindowState = FormWindowState.Minimized;
>
> }
>
>
> }
>


Nov 16 '05 #4
Thanks Nicholas,
I don't believe my app is receiving this message.
It's very difficult to track down as you can't run the app in the debugger
at that level of shutdown.
I stuck a message box in wndproc to show on either message and it didn't
fire.
Nov 16 '05 #5

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

Similar topics

8
by: Les Desser | last post by:
Is there any way to detect within A97 when Windows is trying to shut down, so I can close down the application gracefully? We currently have a trap in the main menu asking the user to confirm if...
3
by: Claire | last post by:
Windows refuses to close down if my applications main form is hidden and there's a notify icon in the system tray. If I restore the form, then shutting down Windows succeeds. If I comment out the...
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...
3
by: Myo Zaw | last post by:
hi, i have a windows service that check to the external web site httpwebresponse and save the result into log text file. and, my problem is when i shut down my system, i also would like to save...
7
by: Mark Rae | last post by:
Hi, I wrote a Windows service for a client a few months ago, and the client has now asked me to modify it so that it shuts itself down under certain circumstances e.g. a catastrophic failure of...
5
by: Jeff S | last post by:
I'm creating a new Windows Forms MDI application... How can I add cause the application to shut itself down after a period of ? I did this in an old COM/VB6 application and I had to have code...
3
by: diffuser78 | last post by:
I am a newbie in Python and want your help in writing python script. I have to remotely shut the windows px from linux box. I run OpenSSH on windows PC. I remotely connect it from Linux box using...
6
sashi
by: sashi | last post by:
Shut down Windows For various reasons you may require a shut down of Windows to happen programmatically. For instance if the installation of your program requires system reconfiguration. The...
2
by: =?Utf-8?B?R2xlbm4=?= | last post by:
i just upgraded from XP to Vista and so far am kicking myself for it. After I installed and got all my drivers updated i went to shut down windows and it will not shut down. It closes all programs...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.