Example #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="backoffPolicy">BackOff Policy</param>
 /// <param name="factor">Parameter used to calculate backoff</param>
 /// <param name="retryLimit">Retry Limit</param>
 /// <param name="timeLimit">Time Limit</param>
 public RetryPolicy(IBackoffPolicy backoffPolicy, int factor, int retryLimit, TimeSpan?timeLimit = default(TimeSpan?))
 {
     BackoffPolicy = backoffPolicy;
     Factor        = factor;
     RetryLimit    = retryLimit;
     TimeLimit     = timeLimit;
 }
        private static void RepeatTillTimeout(VoidFunction voidFunction, TimeSpan timeout, IBackoffPolicy backoffPolicy)
        {
            var stopwatch = Stopwatch.StartNew();

            while (stopwatch.Elapsed < timeout)
            {
                try
                {
                    voidFunction();
                }
                catch (Exception e)
                {
                    Trace.WriteLine(e);
                }
                backoffPolicy.Wait();
            }
        }