简体   繁体   English

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

[英]My C# program running as Windows Service is blocking Windows XP from hibernation

I have Windows Service written in C#. 我有用C#编写的Windows服务。 It starts two threads, one is pooling a Web Service, second is waiting on a Monitor object for a new job to arrive. 它启动两个线程,一个是池化Web服务,第二个是在Monitor对象上等待新作业到达。 Besides that, the main thread acts as a WCF service host using NetNamedPipeBinding . 除此之外,主线程使用NetNamedPipeBinding充当WCF服务主机。 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. 我遇到的问题是,当这个Windows服务运行时,我无法休眠或待机在Windows XP,SP3上运行的计算机。 When I set Windows to hibernate or standby, nothing happens. 当我将Windows设置为休眠或待机状态时,没有任何反应。 Then, at the moment when I go to Service Manager and stop the service, the system hibernation starts immediately. 然后,在我转到Service Manager并停止服务的那一刻,系统休眠立即开始。

The service class extending the ServiceBase has properties like CanHandlePowerEvent, CanPauseAndContinue, etc. set to true... That didn't make any difference. 扩展ServiceBase的服务类具有CanHandlePowerEvent,CanPauseAndContinue等属性设置为true ...这没有任何区别。

The question is: what can be blocking the Hibernation/Standby from proceeding? 问题是:什么可以阻止休眠/待机进行? What should I take care about to avoid it? 我应该注意什么来避免它?

You only mention that you set the CanHandlePowerEvent property to true. 您只提到将CanHandlePowerEvent属性设置为true。 I assume that you'll also have to handle the OnPowerEvent and return true if the status is QuerySuspend and also probably stop anything you're doing, though I don't know the details of this. 我假设您还必须处理OnPowerEvent并在状态为QuerySuspend返回true ,并且可能会阻止您正在执行的任何操作,但我不知道其中的详细信息。

More details here: 更多细节在这里:

http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicebase.onpowerevent%28v=VS.80%29.aspx http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicebase.onpowerevent%28v=VS.80%29.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Windows XP上运行的ac#程序中进行图像扫描 - image scanning in a c# program running on Windows XP 如何在C#中知道程序在运行XP SP2的Mac上的Parallels上运行,还是在运行Windows 7的Mac上的VmWare上运行 - How to know in C# that program is running on Parallels on a Mac running XP SP2 or VmWare on a Mac running Windows 7 在Windows 8中运行但在Windows 7中未运行的C#服务 - The C# service running in Windows 8 but is not running in Windows 7 C#中的Windows服务程序 - windows service program in C# Windows XP下的程序路径(C#程序) - Program path under Windows XP(C# program) 如果未在管理模式下运行,如何阻止我的程序运行? XP和Windows 7 - How can I prevent my program from running if it is not ran in Administrative mode? XP and Windows 7 在 Windows XP 中使用 .net Framework 4.5.2 制作 C# 程序 - Make a C# program with .net Framework 4.5.2 work in Windows XP 关闭Windows XP后,C#应用程序继续运行 - C# application keep running after closing windows XP 在Windows XP计算机上运行SlimDX C#应用程序时遇到的麻烦 - troubles with running SlimDX C# application on Windows XP machine 从Windows 7命令行运行时,为什么我的C#程序会经常暂停? - Why does my C# program pause so often when running from the Windows 7 command line?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM