In the Windows service, I need to determine when the computer goes into sleep mode and when it wakes up, and run some code for these events. This must be done for standby, standby, and sleep.
How to do it?
Override the ServiceBase.OnPowerEvent () method.
I'm not sure because I never did this myself, but recently I went through the OnSessionChange method. I can not promise that this allows you to catch a sleep event, but maybe studying its documentation on MSDN or elswere can help you.
http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicebase.canhandlesessionchangeevent.aspx