Exemple #1
0
        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);
        }
Exemple #2
0
        public TTickTimer CloseTickTimer(ETickTimer timer)
        {
            TTickTimer tTimer = (TTickTimer)TickTimers[timer];

            tTimer.Timer.Stop();
            tTimer.Timer.Dispose();
            TickTimers.Remove(timer);

            return(tTimer);
        }
Exemple #3
0
        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();
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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();
        }