【发布时间】:2014-08-22 02:45:52
【问题描述】:
我制作了一个窗口服务,它在每个之后执行一个操作。我们将定时器声明如下:
using System.Timers;
....
Int32 myInterval = 60000 * (Convert.ToInt32(ConfigurationManager.AppSettings["lpInterval"].ToString()));
_myTimer = new Timer();
_myTimer.Interval = myInterval;
_myTimer.Elapsed += new ElapsedEventHandler(TimerElapsed);
//Timer-Tick
private void TimerElapsed(object source, ElapsedEventArgs e)
{ PerformAction(); }
注意到了什么:
如果PerformAction() 比我的interval 花费的时间更长(由于WCF 服务或服务器问题),则启动并执行PerformAction 的新'instance'。所以PerformAction 彼此运行两次(和parallel)。
这是什么原因?为什么之前的PerformAction 没有被取消?方法PerformAction是否正在执行Async?
我找到了解决方法,但我就是不明白这种行为...
【问题讨论】:
标签: c# windows-services system.timers.timer