问题
I have a service written in C# that does not seem to come down cleanly when the computer enters sleep mode. The user needs to manually stop and restart the service to retain functionality. I know what the issue is but I am not sure where to fix it. How do Windows services behave when going into/come out of sleep and hibernate?
回答1:
How do services react to power events? Really, it depends.
In your service you can handle the hibernate/suspend/etc events by handling it in your service
protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
{
//do stuff here
}
来源:https://stackoverflow.com/questions/11367318/how-do-windows-services-behave-when-entering-waking-up-from-sleep-or-hibernate-m