Windows服务在不同计时器上运行任务

时间:2016-05-10 11:59:12

标签: c# windows service

我有一个Windows服务,我需要做两件事,每15分钟一次,每天一次。使用2个定时器来执行此操作是否有效,类似于下面的内容?

protected override void OnStart(string[] args)
{
    Console.WriteLine("start");
    this.regularTimer = new System.Timers.Timer(300000D);
    this.regularTimer.AutoReset = true;
    this.regularTimer.Elapsed += new System.Timers.ElapsedEventHandler(this.DoRegular);
    this.regularTimer.Start();

    this.longTimer = new System.Timers.Timer(86400000D);
    this.longTimer.AutoReset = true;
    this.longTimer.Elapsed += new System.Timers.ElapsedEventHandler(this.DoLongRunning);
    this.longTimer.Start();
}

0 个答案:

没有答案