Click here to Skip to main content
15,895,815 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have created a window service in c# it run perfectly
but the issue is when the computer shut downs my service doesn't stop
because of these on the next startup my service show running status but it does not executes the code in it...

any suggestion or a rough idea would be appreciated
Posted
Comments
Sergey Alexandrovich Kryukov 28-Nov-15 1:32am    
This is amazing. Please teach me how to achieve such thing. I also want to be able to develop a service which can work when a computer is shut down.
—SA
Salman622 28-Nov-15 1:38am    
Mr. sergey Alexandrovich actually you get it wrong

i mean to say before shutdown my service should stop but its not stopping and i want to achieved that.
Sergey Alexandrovich Kryukov 28-Nov-15 15:18pm    
Sure, I understand that. What I mean to say, you should better express yourself more accurately, to avoid confusions. :-)
Anyway, now I answered your question; please see Solution 2.

Thank you.
—SA

ServiceBase has an OnStop() which you should override and handle the clean shutdown of your service internal code.
 
Share this answer
 
You can achieve what you want using the class: Microsoft.Win32.SystemEvents:
https://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents%28v=vs.110%29.aspx[^].

—SA
 
Share this answer
 

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