public static void Action(Action action, Action<Exception> onRetry, int retryAttempts, BackOff backoff) { Mandate.ParameterNotNull(action, "action"); Mandate.ParameterNotNull(backoff, "backoff"); backoff.Reset(); int retryCount = retryAttempts; do { try { action(); return; } catch (Exception ex) { if (retryCount <= 0) { throw; } onRetry(ex); backoff.Delay(); } } while (retryCount-- > 0); }
private static void SlowDownPollingIfNoWorkAvailable(bool foundWork, BackOff backoff) { if (foundWork) { backoff.Reset(); } else { backoff.Delay(); } }
private void WorkerAction(object obj) { var backoff = new BackOff(TimeSpan.FromMilliseconds(10), TimeSpan.FromSeconds(5)); var cancellationToken = (CancellationToken)obj; while (!cancellationToken.IsCancellationRequested) { if (TryProcessNextTimeout()) { backoff.Reset(); } else { backoff.Delay(); } } }