How do Windows services behave when entering/waking up from sleep or hibernate modes?

社会主义新天地 提交于 2019-12-21 11:32:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!