Exemplo n.º 1
0
 private async void BackgroundThreadAsync()
 {
     // We check _running just before the event could be raised to avoid events being raised after this class is disposed
     while (_running)
     {
         var waitToNextTimeout = _lastReset + _timeout - DateTime.UtcNow;
         if (waitToNextTimeout <= TimeSpan.Zero)
         {
             TimeoutReached?.Invoke(this, new EventArgs());
             _lastReset        = DateTime.UtcNow;
             waitToNextTimeout = _timeout;
         }
         // The above makes sure that the delay cannot be negative
         await Task.Delay(waitToNextTimeout);
     }
 }
Exemplo n.º 2
0
 private void TimeoutReachedHandler(object sender, ElapsedEventArgs e)
 {
     Stop();
     TimeoutReached?.Invoke(sender, e);
 }
Exemplo n.º 3
0
 protected virtual void OnTimeoutReached()
 {
     TimeoutReached?.Invoke(this, EventArgs.Empty);
 }