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?
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.
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".
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.
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:
...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With