المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Closing application when windows shuts down



C# Programming
02-22-2010, 07:52 PM
Hi,

I have wriiten a little application that runs mainly in the background. There is a U.I. trhat can be accessed by double clicking its icon in the notification bar. The problem is when I try to restart or shut down my XP machine the application will not close. This appears to be not an issue on Windows 7 as it shutsdown fine, I suspect Vista could be ok also.

I checked the event viewer the event was to the effect The attempt to reboot PC failed. I have read a little and I added the following to my code

// 1. Global variable in main form
private int WM_QUERYENDSESSION = 0x11;

//2. Override WndProc
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_QUERYENDSESSION)
{
Application.ExitThread();
}
base.WndProc(ref m);
}
This works in as much as the application closes when I try to restart my machine, but the machine does not restart I have to tell to restart once more before it restarts. I feel it's almost there but I am not sure what is missing.

Help if you can, Dave.