Exemple #1
0
        public void Start(double timeToEvent, int interval)
        {
            try
            {
                _timeToEventCurrent = timeToEvent;
                _timeToEventSeconds = (int)Math.Floor(timeToEvent) + 1;

                switch (TimerMode)
                {
                case "Timer":
                    if (_timer == null)
                    {
                        _timer          = new Timer(interval);
                        _timer.Elapsed += delegate { TickHandler(); };
                    }
                    else
                    {
                        _timer.Interval = interval;
                    }
                    _timer.Start();
                    break;

                case "MicroTimer":
                    if (_microTimer == null)
                    {
                        _microTimer = new MicroTimer((interval * 1000));
                        _microTimer.MicroTimerElapsed += delegate { TickHandler(); };
                    }
                    else
                    {
                        _microTimer.Interval = (interval * 1000);
                    }
                    _microTimer.Start();
                    break;
                }
                _stopWatch.Start();
                Enabled = true;
                LogHelper.Log(Logger, TimerMode + " Started ( Duration:" + timeToEvent + " Interval:" + interval + " Sound When Finished:" + SoundWhenFinished + " Volume:" + Volume + " Counting:" + Counting + " )", LogLevel.Debug);
            }
            catch (Exception ex)
            {
                LogHelper.Log(Logger, ex, LogLevel.Error);
            }
        }
        public void Start(double timeToEvent, int interval)
        {
            try
            {
                _timeToEventCurrent = timeToEvent;
                _timeToEventSeconds = (int) Math.Floor(timeToEvent) + 1;

                switch (TimerMode)
                {
                    case "Timer":
                        if (_timer == null)
                        {
                            _timer = new Timer(interval);
                            _timer.Elapsed += delegate { TickHandler(); };
                        }
                        else
                        {
                            _timer.Interval = interval;
                        }
                        _timer.Start();
                        break;

                    case "MicroTimer":
                        if (_microTimer == null)
                        {
                            _microTimer = new MicroTimer((interval * 1000));
                            _microTimer.MicroTimerElapsed += delegate { TickHandler(); };
                        }
                        else
                        {
                            _microTimer.Interval = (interval * 1000);
                        }
                        _microTimer.Start();
                        break;
                }
                _stopWatch.Start();
                Enabled = true;
                LogHelper.Log(Logger, TimerMode + " Started ( Duration:" + timeToEvent +" Interval:" + interval + " Sound When Finished:" + SoundWhenFinished + " Volume:" + Volume + " Counting:" + Counting + " )", LogLevel.Debug);
            }
            catch (Exception ex)
            {
                LogHelper.Log(Logger, ex, LogLevel.Error);
            }
        }