Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check when the computer is being put to sleep or wakes up?

I want to make my program aware of the computer being put to sleep or waking up from sleep, possibly have an event that is triggered when either of these occur. Is this possible?

like image 606
esac Avatar asked Oct 13 '09 19:10

esac


People also ask

How can I see when my computer was turned on?

To identify what woke your PC up: Search for Command Prompt in the Start menu. Right-click and press "Run as administrator". Run the following command: powercfg -lastwake.

How do I stop my computer from waking from sleep mode?

You may disable this ability by locating your PC's Network Adapter in Device Manager and opening the Properties window. Then, click the Power Management tab and uncheck the box for "Allow this device to wake the computer".

Do computers go to sleep automatically?

Windows 10 also puts your computer to sleep automatically. The sleep settings let you choose when the computer should go to sleep and, if you wish, when it should automatically wake up. To adjust sleep settings, go to the Power Options control panel.


1 Answers

You can subscribe to the SystemEvents.PowerModeChanged event.

SystemEvents.PowerModeChanged += OnPowerChange;

void OnPowerChange(Object sender, PowerModeChangedEventArgs e) {
  switch ( e.Mode ) {
    case PowerModes.Resume: 
      ...
    case PowerModes.Suspend:
      ...
  }
}
like image 115
JaredPar Avatar answered Sep 18 '22 12:09

JaredPar