I have an application which does a specific task after some time (controlled by a timer). But whenever I start PC after hibernate that application runs. This means that timer keeps running during hibernation for atleast one tick. How can I avoid this.
You can handle the SystemEvents.PowerModeChanged event to stop the timer when the machine is suspending and start it again when it is resuming.
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
...
void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
{
if (e.Mode == PowerModes.Suspend) PauseTimer();
else if (e.Mode == PowerModes.Resume) ResumeTimer();
}
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