我作为 Windows 服务运行的 C# 程序阻止 Windows XP 休眠
我有用 C# 编写的 Windows 服务。它启动两个线程,一个正在池化 Web 服务,第二个正在等待 Monitor 对象以等待新作业到达。除此之外,主线程使用 NetNamedPipeBinding 充当 WCF 服务主机。它允许客户端应用程序注册回调,然后发回通知。
我遇到的问题是,当此 Windows 服务运行时,我无法休眠或待机在 Windows XP、SP3 上运行的计算机。当我将 Windows 设置为休眠或待机时,没有任何反应。然后,当我进入服务管理器并停止服务时,系统休眠立即开始。
扩展 ServiceBase
的服务类将 CanHandlePowerEvent、CanPauseAndContinue 等属性设置为 true...这没有任何区别。
问题是:什么会阻止休眠/待机的进行?我应该注意什么才能避免呢?
I have Windows Service written in C#. It starts two threads, one is pooling a Web Service, second is waiting on a Monitor object for a new job to arrive. Besides that, the main thread acts as a WCF service host using NetNamedPipeBinding
. It lets the client application to register a callback and then sends notifications back.
The problem I have is that when this Windows Service is running, I cannot hibernate or Standby my computer which is running on Windows XP, SP3. When I set Windows to hibernate or standby, nothing happens. Then, at the moment when I go to Service Manager and stop the service, the system hibernation starts immediately.
The service class extending the ServiceBase
has properties like CanHandlePowerEvent, CanPauseAndContinue, etc. set to true... That didn't make any difference.
The question is: what can be blocking the Hibernation/Standby from proceeding? What should I take care about to avoid it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您仅提到将
CanHandlePowerEvent
属性设置为 true。我假设您还必须处理OnPowerEvent
并在状态为QuerySuspend
时返回true
,并且还可能停止您正在执行的任何操作,虽然我不知道这件事的细节。更多详细信息请参见:
http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicebase.onpowerevent%28v=VS.80%29.aspx
You only mention that you set the
CanHandlePowerEvent
property to true. I assume that you'll also have to handle theOnPowerEvent
and returntrue
if the status isQuerySuspend
and also probably stop anything you're doing, though I don't know the details of this.More details here:
http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicebase.onpowerevent%28v=VS.80%29.aspx