using System; using System.Timers; namespace Jd.ACES.Utils { public delegate void ScheduleTask(Object obj, ElapsedEventArgs e); public class ScheduledExecutor : Timer { /// /// Constructor of ScheduledExecutor with given interval and given task. /// /// The given interval, unit is second. /// The given task to execute repeatedly. public ScheduledExecutor(double interval, ScheduleTask task) { this.Interval = interval * 1000; this.Elapsed += new ElapsedEventHandler(task); this.AutoReset = true; this.Enabled = true; } /// /// Sets the interval, in seconds, for repeated execution. /// /// The given interval, unit is second. public void SetExecuteInterval(long interval) { this.Interval = interval * 1000; } } }