Esempio n. 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);
        }
Esempio n. 2
0
        public void WorkerAction(object obj)
        {
            var backoff = new BackOff(TimeSpan.FromMilliseconds(1), TimeSpan.FromMilliseconds(1000));
            var cancellationToken = (CancellationToken)obj;

            while (!cancellationToken.IsCancellationRequested)
            {
                bool foundWork = DequeueWork();
                SlowDownPollingIfNoWorkAvailable(foundWork, backoff);
            }
        }
Esempio n. 3
0
 private static void SlowDownPollingIfNoWorkAvailable(bool foundWork, BackOff backoff)
 {
     if (foundWork)
     {
         backoff.Reset();
     }
     else
     {
         backoff.Delay();
     }
 }
Esempio n. 4
0
 public static void Action(Action action, int retryAttempts, BackOff backOff)
 {
     Action(action, (arg1) => { }, retryAttempts, backOff);
 }
        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();
                }
            }
        }