public class PluginTimedEvent
{
private Dictionary<string, object> _args;
private readonly System.Timers.Timer _timer;
private long lastTick;
private int _elapsedCount;
internal delegate void TimedEventFireDelegate(PluginTimedEvent evt);
internal event TimedEventFireDelegate OnFire;
internal PluginTimedEvent(double interval)
{
this._timer = new System.Timers.Timer();
this._timer.Interval = interval;
this._timer.Elapsed += new ElapsedEventHandler(this._timer_Elapsed);
this._elapsedCount = 0;
}
internal PluginTimedEvent(double interval, Dictionary<string, object> args)
: this(interval)
{
this.Args = args;
}
private void _timer_Elapsed(object sender, ElapsedEventArgs e)
{
if (this.OnFire != null)
{
this.OnFire(this);
}
this._elapsedCount += 1;
this.lastTick = DateTime.UtcNow.Ticks;
}
internal void Start()
{
this._timer.Start();
this.lastTick = DateTime.UtcNow.Ticks;
}
internal void Stop()
{
this._timer.Stop();
}
internal void Kill()
{
this._timer.Stop();
this._timer.Dispose();
}
internal Dictionary<string, object> Args
{
get { return this._args; }
set { this._args = value; }
}
internal double Interval
{
get { return this._timer.Interval; }
set { this._timer.Interval = value; }
}
internal double TimeLeft
{
get { return (this.Interval - ((DateTime.UtcNow.Ticks - this.lastTick) / 0x2710L)); }
}
internal int ElapsedCount
{
get { return this._elapsedCount; }
}
}