Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的C#程序作为Windows服务运行,正在阻止Windows XP进入休眠状态_C#_.net_Windows Services_Hibernation - Fatal编程技术网

我的C#程序作为Windows服务运行,正在阻止Windows XP进入休眠状态

我的C#程序作为Windows服务运行,正在阻止Windows XP进入休眠状态,c#,.net,windows-services,hibernation,C#,.net,Windows Services,Hibernation,我用C#编写了Windows服务。它启动两个线程,一个是共享一个Web服务,第二个是等待一个监视对象,等待一个新作业到达。除此之外,主线程还使用NetNamedPipeBinding充当WCF服务主机。它允许客户端应用程序注册回调,然后发送回通知 我的问题是,当此Windows服务运行时,我无法休眠或待机运行在Windows XP、SP3上的计算机。当我将Windows设置为休眠或待机时,什么也不会发生。然后,当我转到Service Manager并停止服务时,系统休眠立即开始 扩展Servic

我用C#编写了Windows服务。它启动两个线程,一个是共享一个Web服务,第二个是等待一个监视对象,等待一个新作业到达。除此之外,主线程还使用
NetNamedPipeBinding
充当WCF服务主机。它允许客户端应用程序注册回调,然后发送回通知

我的问题是,当此Windows服务运行时,我无法休眠或待机运行在Windows XP、SP3上的计算机。当我将Windows设置为休眠或待机时,什么也不会发生。然后,当我转到Service Manager并停止服务时,系统休眠立即开始

扩展
ServiceBase
的服务类的属性如CanHandlePowerPrevent、CanPauseAndContinue等设置为true。。。那没什么区别


问题是:什么会阻止休眠/待机继续?我应该注意什么来避免它?

您只提到您将
canhandlepowerprevent
属性设置为true。我假设如果状态为
QuerySuspend
,您还必须处理
OnPowerEvent
并返回
true
,还可能停止您正在做的任何事情,尽管我不知道这方面的细节

详情如下:


我实现了OnPowerEvent,返回始终为true。但这还不够。但是,有帮助的是手动关闭调用ServiceHost.Close()的WCF连接。显然,WCF频道不会在这次活动中自动中止,但不知道细节——我是这方面的新手。谢谢