以下代码在正常情况下每两分钟就会很好地记录下来:
Observable.Interval(TimeSpan.FromSeconds(120)).Subscribe(
l =>
{
var now = DateTime.Now;
Console.WriteLine(
"Tick at " + now.ToString("hh:mm:ss") + " Count " + l.ToString());
});
Tick at 11:30:00 Count 0
(11:31:55 put computer to sleep)
(no tick at 11:32:00 because PC is suspended, which is fine)
(no tick at 11:34:00 because PC is suspended)
(11:34:30 wake computer up)
(no tick as soon as possible to indicate that ticks were missed)
Tick at 11:36:30 Count 1
似乎Observable Interval计时器会重置自身并从设备恢复时开始重新开始间隔。 (我观察到与Observable Timer类似的行为)
我需要一个不会在恢复时重启间隔的计时器,但如果在睡眠期间错过了任何刻度,则需要一次计时