private void CheckForTimeout(object sender, TimerTickEventArgs e)
        {
            bool isRunning = _timeout > TimeSpan.Zero;
            if (!isRunning)
            {
                return;
            }

            _timeout -= e.ElapsedTime;

            bool isElapsed = _timeout <= TimeSpan.Zero;
            if (!isElapsed)
            {
                return;
            }

            try
            {
                _action?.Invoke();
            }
            finally
            {
                if (_interval == TimeSpan.Zero)
                {
                    Cancel();
                }
                else
                {
                    _timeout = _interval;
                }
            }
        }
        private void Tick(object sender, TimerTickEventArgs e)
        {
            if (_ledTimeout.IsRunning)
            {
                _ledTimeout.Tick(e.ElapsedTime);
                if (_ledTimeout.IsElapsed)
                {
                    ToggleStatusLed();
                }
            }

            _durations.Add((int)e.ElapsedTime.TotalMilliseconds);
            if (_durations.Count == _durations.Capacity)
            {
                _averageTimerDuration = _durations.Sum() / (float)_durations.Count;
                _durations.Clear();

                if (!_maxTimerDuration.HasValue || _averageTimerDuration > _maxTimerDuration.Value)
                {
                    _maxTimerDuration = _averageTimerDuration;
                }

                if (!_minTimerDuration.HasValue || _averageTimerDuration < _minTimerDuration.Value)
                {
                    _minTimerDuration = _averageTimerDuration;
                }
            }
        }
Esempio n. 3
0
        private void CheckForTimeout(object sender, TimerTickEventArgs e)
        {
            if (!_stopwatch.IsRunning)
            {
                return;
            }

            if (_stopwatch.Elapsed > TimeoutForPressedLongActions)
            {
                _stopwatch.Stop();
                OnPressedLong();
            }
        }
        private void UpdatePosition(TimerTickEventArgs timerTickEventArgs)
        {
            if (State == RollerShutterState.MovingUp)
            {
                _position -= (int)timerTickEventArgs.ElapsedTime.TotalMilliseconds;
            }
            else if (State == RollerShutterState.MovingDown)
            {
                _position += (int)timerTickEventArgs.ElapsedTime.TotalMilliseconds;
            }

            if (_position < 0)
            {
                _position = 0;
            }

            if (_position > _positionMax)
            {
                _position = _positionMax;
            }
        }
 private void ApplyFrame(object sender, TimerTickEventArgs timerTickEventArgs)
 {
     _position += timerTickEventArgs.ElapsedTime;
     ApplyFrame();
 }