예제 #1
0
        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);
        }
예제 #2
0
파일: Receiver.cs 프로젝트: kehinze/Hermes
 private static void SlowDownPollingIfNoWorkAvailable(bool foundWork, BackOff backoff)
 {
     if (foundWork)
     {
         backoff.Reset();
     }
     else
     {
         backoff.Delay();
     }
 }
예제 #3
0
        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();
                }
            }
        }