views:

172

answers:

2

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?

+3  A: 

You only mention that you set the CanHandlePowerEvent property to 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 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

ho1
I had OnPowerEvent implemented returning always true. But that wasn't enough. However what helped was closing the WCF connection calling ServiceHost.Close() manually. Apparently the WCF channel does not get aborted automatically on this event but don't know details - I'm a newbie in this. Thanks.
sherpa
A: 

if you tray to run the service while computer is hibernated, try to change the user service runnig

fructas