Click here to Skip to main content
15,910,661 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to stop shut down until my C#.net windows app is running.That is even when
user shutdowns pc i need code that abort this shutdown
Posted
Comments
Sergey Alexandrovich Kryukov 24-Feb-13 22:45pm    
Abort shutdown and delay shutdown until your application is running are different things. You can do first, but an attempt to do the second is useless.
—SA

You can't. There are so many ways a user can force your app to be terminated it's silly.

You're kidding yourself if you think you can. It's like believing you can protect images being copied off websites - it's impossible.

Sorry, but users will kill your app one way or another (eg. power off). The question is how you nicely handle the shutdown.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 24-Feb-13 23:06pm    
Agree, my 5, with one clarification: it's of course possible to abort previously initiated shutdown, but... I don't even want to discuss using it for preventing of the shutdown until some application is running, bad idea. Please see my answer.
—SA
Please see my comment to the question.

You can abort initiated shutdown using the command "shutdown /a". So, programmatically,
C#
System.Diagnostics.Process.Start("shutdown", "/a");


But it cannot help you to keep the system working until your application is executed. The whole idea is wrong; and the author of the Solution 1 is right.

—SA
 
Share this answer
 
Comments
fdiu 24-Feb-13 23:27pm    
i do this but error like the application was unable to start currectly click ok to close
Sergey Alexandrovich Kryukov 24-Feb-13 23:31pm    
Did you run it under debugger? Could be too many reasons for that.
But I answered not for you to apply this method. The whole idea is wrong. See Solution 1.
—SA
fdiu 25-Feb-13 6:59am    
sorry for late because of electricity problem.
I got that we can not delay shutdown but can abort .I write code like in forms closing event handler i check the cause ,if it is due to windows shutdown then i want to abort it
Sergey Alexandrovich Kryukov 25-Feb-13 11:55am    
I already answered.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900