Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if windows is going to hibernate or suspend?

Tags:

c#

winapi

I am using

SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(
    SystemEvents_PowerModeChanged
);

to tell when Windows is suspending. But how do I know if it is going into hibernate or suspend?

Is there a .Net or PInvoke method to do this?

like image 544
SamFisher83 Avatar asked May 16 '11 00:05

SamFisher83


1 Answers

You can't tell the difference between hibernate and suspend.

A detailed discussion here.

The takeaway message is that your question presupposes a false dichotomy: It can be hibernate, suspend, or hybrid sleep... and when hybrid sleep transitions from suspend to hibernate user code isn't even running (in fact there may be no code running, the transition happens in case of power loss).

So when the decision to hybrid sleep occurs, the system doesn't know whether it will resume from suspend or from hibernation, and it can't tell you what it doesn't know.

like image 152
Ben Voigt Avatar answered Sep 19 '22 05:09

Ben Voigt