public double Update() { var currentTime = _timeClock.CurrentTime; //we're working with nullables, so just to be safe we should check for values if (currentTime.HasValue && _lastTime.HasValue) { //get the difference in time var diffTime = currentTime.Value - _lastTime.Value; DeltaSeconds = diffTime.TotalSeconds; //does the user want a callback on regular intervals? if (TimerInterval > 0.0) { //compute the intervals for this and previous update var currInterval = (int)(currentTime.Value.TotalSeconds / TimerInterval); var prevInterval = (int)(_lastTime.Value.TotalSeconds / TimerInterval); //has the interval changed since last update? if (currInterval != prevInterval) { //fire interval event //note that this will only be called once per frame at most // so if they interval is too small, you wont get 2+ fires per frame TimerFired?.Invoke(this, null); } } } //cycle old time _lastTime = currentTime; return(DeltaSeconds); }
private void TimerCallback(object state) { var timerId = (string)state; var timer = GetAll().FirstOrDefault(i => string.Equals(i.Id, timerId, StringComparison.OrdinalIgnoreCase)); if (timer != null) { TimerFired?.Invoke(this, new GenericEventArgs <TimerInfo>(timer)); } }
private void TimerCallback(object?state) { var timerId = (string?)state ?? throw new ArgumentNullException(nameof(state)); var timer = GetAll().FirstOrDefault(i => string.Equals(i.Id, timerId, StringComparison.OrdinalIgnoreCase)); if (timer != null) { TimerFired?.Invoke(this, new GenericEventArgs <TimerInfo>(timer)); } }
public double Update() { var currentTime = DateTime.Now; //get the difference in time var diffTime = currentTime - ElapsedTime; DeltaSeconds = diffTime.TotalSeconds; //does the user want a callback on regular intervals? if (TimerInterval > 0.0) { /* * //compute the intervals for this and previous update * int currInterval = (int)(currentTime / TimeSpan.FromSeconds(_timerInterval)); * int prevInterval = (int)(_lastTime / TimeSpan.FromSeconds(_timerInterval)); * * //has the interval changed since last update? * if (currInterval != prevInterval) * { * //fire interval event * //note that this will only be called once per frame at most * // so if they interval is too small, you wont get 2+ fires per frame * TimerFired(this, null); * } */ if (currentTime != ElapsedTime) { TimerFired?.Invoke(this, null); } } //cycle old time ElapsedTime = currentTime; return(DeltaSeconds); }
private void AddOrUpdateSystemTimer(TimerInfo item) { StopTimer(item); if (!ShouldStartTimer(item)) { return; } var startDate = RecordingHelper.GetStartTime(item); var now = DateTime.UtcNow; if (startDate < now) { TimerFired?.Invoke(this, new GenericEventArgs <TimerInfo>(item)); return; } var dueTime = startDate - now; StartTimer(item, dueTime); }
/// <summary> /// Invokes a timer-fired event. /// </summary> protected void InvokeTimerFired() { TimerFired?.Invoke(this, new TimerArgs(this)); }
private void TimerExpired() { // Stop pumping session TimerFired?.Invoke(this, EventArgs.Empty); }