会发生什么事在待机模式下计时器? [英] What happens to timer in standby mode?

查看:303
本文介绍了会发生什么事在待机模式下计时器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的定时器由定时器命名空间。 会发生什么到定时器,当电脑进入睡眠状态或休眠?

I'm using Timer from Timers namespace. What happens to timer when PC goes to sleep or hibernates?

我有计时器设置为6小时延误。

I have timer set to 6 hours delay.

会发生在这些情况下什么。

What will happen in those situations.

1)定时器在小时0会立即睡眠/休眠。然后电脑在唤醒每小时5请问我旁边经过1个小时接下来的6小时定时器火?

1) Timer starts at hour 0 and goes to sleep/hibernation immediately. Then PC wakes at hour 5. Will my timer fire after next 1 hour or after next 6 hours?

2)定时器在小时0会立即睡眠/休眠。然后在PC机每小时7请问我的定时器火灾唤醒只要PC醒来还是会小姐,有一次和消防在接下来的5个小时?它会开始从PC清醒或previous计时,直到下一个事件无缘事件?

2) Timer starts at hour 0 and goes to sleep/hibernation immediately. Then PC wakes at hour 7. Will my timer fire as soon as PC wakes or will it "miss" that one time and fire in next 5 hours? Will it start counting till next event from time of PC waking or from previous "missed" event?

推荐答案

确定。 我问我的朋友,这是他的resutls:

Ok. I asked my friend and this are his resutls:

23:21:32 : Timer started
23:21:35 : PC Goes Sleep
23:22:50 : PC Wakes
23:22:50 : Timer fired
23:23:50 : Timer fired

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace Test
{
    class Program
    {
        static System.Timers.Timer timer;

        static void Main(string[] args)
        {
            timer = new System.Timers.Timer();
            timer.Interval = 60 * 1000;
            timer.AutoReset = true;
            timer.Elapsed += timer_Elapsed;
            timer.Enabled = true;

            Console.WriteLine(String.Format("{0}:{1}:{2} : Timer started", DateTime.Now.ToLocalTime().Hour, DateTime.Now.ToLocalTime().Minute, DateTime.Now.ToLocalTime().Second));

            timer.Start();

            Thread.Sleep(Timeout.Infinite);
        }

        static void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            Console.WriteLine(String.Format("{0}:{1}:{2} : Timer fired", DateTime.Now.ToLocalTime().Hour, DateTime.Now.ToLocalTime().Minute, DateTime.Now.ToLocalTime().Second));
        }
    }
}

因此​​,在短期。 后睡与醒定时检查是否有遗漏的任何事件。如果错过了一次将火从0开始计数,直到下一个事件。

So in short. After sleeping and waking timer checks if it has missed any event. If it missed one it will fire start counting till next event from 0.

这篇关于会发生什么事在待机模式下计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆