[英]How to stop a timer during hibernate/ sleep mode in C# winform application?
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.
但每当我在hibernate之后启动PC时该应用程序就会运行。 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 += SystemEvents_PowerModeChanged;
... ...
void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
{
if (e.Mode == PowerModes.Suspend) PauseTimer();
else if (e.Mode == PowerModes.Resume) ResumeTimer();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.