挂起/恢复PC时,使Windows服务正常停止并正常启动的正确方法是什么? [英] What is the proper way to have a Windows service stop and start gracefully when suspending/resuming a PC?
本文介绍了挂起/恢复PC时,使Windows服务正常停止并正常启动的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当PC断电到挂起模式时,我需要停止Windows服务,并在PC再次恢复时重新启动它.正确的方法是什么?
I need to stop our Windows service when a PC is powered down into Suspend mode and restart it when the PC is resumed again. What is the proper way to do this?
推荐答案
您应该覆盖 PowerBroadcastStatus枚举解释了电源状态.另外,您需要将 ServiceBase.CanHandlePowerEvent属性设置为 true
.
The PowerBroadcastStatus Enumeration explains the power statuses.
Also, you'll need to set the ServiceBase.CanHandlePowerEvent Property to true
.
protected override void OnStart(string[] args)
{
this.CanHandlePowerEvent = true;
}
这篇关于挂起/恢复PC时,使Windows服务正常停止并正常启动的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文