0

I am writing a windows service application in .NET/C#.

My service has to be notified when the system enters in hibernation(S4). How to do this in code?

Looks like ServiceBase.OnPowerEvent() method does not notify about the hibernation(S4) event.

James Z
  • 12,209
  • 10
  • 24
  • 44
ARR
  • 1
  • 1
  • [Apparently](https://stackoverflow.com/a/6187658/21567), there is no difference between hibernate and suspend from the point of view of detecting one or the other. So you would handle `QuerySuspend` and/or `Suspend` power states. – Christian.K Mar 23 '22 at 08:13
  • Thanks.. Is there a way to specifically identify whether it is a Sleep or a Hibernate? PowerBroadcastStatus value caught seems to be "Suspend" for both cases. – ARR Mar 24 '22 at 04:55
  • That's the whole point of the linked Q&A - there is no way to differentiate them. – Christian.K Mar 24 '22 at 06:59
  • Thanks.. Is there any way to capture all the system power events(S1,S2,S3,S4,S5) in windows service?. Our intention is to inform app that how many times system has entered all these states. – ARR Mar 24 '22 at 10:23
  • From all *I* know, you can't. Again, there is no obvious distinction between the kind of "suspend" the system is performing in the notification it sends to applications (incl. services). Also see [PBT_APMSUSPEND](https://learn.microsoft.com/en-us/windows/win32/power/pbt-apmsuspend) native message. There might be some heuristic or other ways to find out, but I don't know them. – Christian.K Mar 24 '22 at 11:40

0 Answers0