Reputation: 6148
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.
Upvotes: 9
Views: 5031
Reputation: 1059
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();
}
Upvotes: 18