views:

43

answers:

2

I have this C# app which starts at system boot in the tray, and i have the following problem with it, only on Windows XP

I can't restart the PC while the application is running. If I use file > exit, it stops ok and then i can restart. but if i try restarting with the application open, it just won't do it

I tried adding this in the main window constructor, dunno if its the right thing to do:

Application.ApplicationExit += new EventHandler(this.OnApplicationExit);

and the OnApplicationExit function does the app's shutting down procedure.. but that doesn't help

any ideas?

+2  A: 

Do you have a FormClosing event handler somewhere where you do something like e.Cancel = true;?

If so, change it to first look at the close reason to decide if it should cancel or not as:

if(e.CloseReason != WindowsShutDown)
     e.Cancel = true;

There might be other CloseReasons where you should also not Cancel the closing so might be worth looking at MSDN for that.

ho1
That seemed to solve my problem. I would have never imagine my application could block the entire system. Thank you!
andrew
+1  A: 

Hi Andrew,

I've seen this happen before if you've got Cancel = true somewhere in your exit handler.

Fidel
Don't know why this got downvoted, might not be completely clear, but it's still clear enough to be helpful, so +1 to compensate.
ho1