Exemple #1
0
        private TimerEx GetTimer(long timeLeft, IServiceCallback callback)
        {
            TimerEx timerEx = new TimerEx();

            timerEx.Interval = 1000;
            timerEx.Elapsed += TimerExOnElapsed;
            timerEx.Id       = Guid.NewGuid().ToString();
            timerEx.TimeLeft = timeLeft;
            timerEx.Callback = callback;

            return(timerEx);
        }
Exemple #2
0
        private void TimerExOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
        {
            try
            {
                TimerEx timer = sender as TimerEx;

                if (timer != null)
                {
                    if (timer.TimeLeft-- == 0)
                    {
                        timer.Stop();
                        timer.Callback.ForciblyReturnTestResult();
                    }
                    else
                    {
                        timer.Callback.SetRemainingTime(timer.TimeLeft);
                    }
                }
            }
            catch (Exception)
            {
                // ignored
            }
        }