using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.ServiceProcess;
using System.Timers;

namespace Pub.Class {
public abstract class TaskServiceBase : ServiceBase {

private Timer timer = new Timer();

public TaskServiceBase(TimeSpan interval) {
timer.Elapsed
+= new ElapsedEventHandler(timer_Elapsed);
timer.Interval
= interval.TotalMilliseconds;
timer.AutoReset
= false;
timer.Enabled
= false;
}

protected override void OnStart(string[] args) { timer.Start(); }

protected override void OnStop() { timer.Stop(); }

protected abstract void RunTask();

private void timer_Elapsed(object sender, ElapsedEventArgs e) {
timer.Stop();
try { RunTask(); } finally { timer.Start(); }
}

}
}

 

相关文章:

  • 2022-02-22
  • 2021-12-25
  • 2022-03-08
  • 2021-05-29
  • 2021-12-06
  • 2021-09-21
  • 2022-03-04
猜你喜欢
  • 2021-05-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
  • 2022-12-23
  • 2021-05-18
相关资源
相似解决方案