public Guid InitTimer(ETimerType timerType, TickController controller, int interval, Guid guid) { switch (timerType) { case ETimerType.System: { System.Timers.Timer wTimer = new System.Timers.Timer(); wTimer.Interval = interval * 1000; wTimer.Elapsed += new ElapsedEventHandler(Timer_Elapsed); TickTimers.Add(guid, new TTimer { Guid = guid, Type = timerType, Timer = wTimer, Controller = controller }); wTimer.Start(); } break; case ETimerType.Form: { System.Windows.Forms.Timer wTimer = new System.Windows.Forms.Timer(); wTimer.Interval = interval * 1000; wTimer.Tick += new EventHandler(Timer_Tick); TickTimers.Add(guid, new TTimer { Guid = guid, Type = timerType, Timer = wTimer, Controller = controller }); wTimer.Start(); } break; } return(guid); }
public TTickTimer CloseTickTimer(ETickTimer timer) { TTickTimer tTimer = (TTickTimer)TickTimers[timer]; tTimer.Timer.Stop(); tTimer.Timer.Dispose(); TickTimers.Remove(timer); return(tTimer); }
public void InitTickTimer(ETickTimer eTimer, TickController tickController, double interval) { System.Windows.Forms.Timer wTimer = new System.Windows.Forms.Timer(); wTimer.Tick += new System.EventHandler(Timer_Tick); wTimer.Interval = (int)(interval * 1000); TickTimers.Add(eTimer, new TTickTimer { Timer = wTimer, Controller = tickController }); wTimer.Enabled = true; wTimer.Start(); }
public TTimer CloseTimer(Guid id) { TTimer tTimer = new TTimer(); if (!TickTimers.ContainsKey(id)) { return(tTimer); } tTimer = (TTimer)TickTimers[id]; tTimer.CloseTimer(); TickTimers.Remove(id); return(tTimer); }
private void Timer_Tick(object sender, EventArgs e) { KeyValuePair <ETickTimer, TTickTimer> entry = TickTimers.First(item => ((TTickTimer)item.Value).Timer == (System.Windows.Forms.Timer)sender); ((TTickTimer)(entry.Value)).Controller(); }