Пример #1
0
        private static void TempDataRetry(Action callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback));
            }

            List <Exception> exceptions = null;
            var throttleDelay           = TimeSpan.FromMilliseconds(100);
            var maxThrottleDelay        = TimeSpan.FromSeconds(10);

            for (var i = 0; i < 5; i++)
            {
                try
                {
                    callback();
                    break;
                }
                catch (IOException ex)
                {
                    ex.LogToCodeTraceSourceOnCatch(true);
                    exceptions ??= new List <Exception>();
                    exceptions.Add(ex);

                    var delay = TimeoutHelper.ExponentialBackoffTimeout(i + 1, throttleDelay, maxThrottleDelay);

#if TARGETS_NET || NETSTANDARD20_OR_GREATER || TARGETS_NETCOREAPP
                    Thread.Sleep(delay);
#else
                    Task.Delay(delay).Wait();
#endif
                }
            }

            if (exceptions != null)
            {
                var exception = new AggregateException(exceptions);
                throw exception.LogToCodeTraceSourceBeforeThrow();
            }
        }