【发布时间】:2010-05-05 18:48:33
【问题描述】:
我有一个 System.Timer 设置来每天凌晨 2 点触发一个事件。 如果计时器启动的过程失败,那么我想要计时器 重置为每 15 分钟运行一次,直到该过程成功完成。
// this is how the timer is set up.
// this is working correctly.
double startTime = milliseconds_of_hour_to_start.
Timer = new System.Timers.Timer( startTime);
这是在事件处理程序成功或失败时重置计时器的代码。 注意计时器没有停止, 只是 Interval 属性正在重置。
if (ProcessSuccess)
{
Timer.Interval = TimeSpan.FromHours(24).TotalMilliseconds;
}
else
{
Timer.Interval = TimeSpan.FromMinutes(15).TotalMilliseconds;
}
我的问题是,如果这个过程失败了 4 次,那么定时器现在会在凌晨 3 点左右运行吗? 即失败后,凌晨 2 点的原始开始时间会提前 15 分钟吗?
【问题讨论】:
-
未来的实现可能值得关注quartznet.sourceforge.net。我总是更喜欢查看现有的可以重用的库而不是自己编写的库