<PackageReference Include="Polly" Version="2.2.3" />

RetryPolicyStateWithCount

using System; namespace Polly.Retry { internal class RetryPolicyStateWithCount : IRetryPolicyState { private int _errorCount; private readonly int _retryCount; private readonly Action<Exception, int, Context> _onRetry; private readonly Context _context; public RetryPolicyStateWithCount(int retryCount, Action<Exception, int, Context> onRetry, Context context) { _retryCount = retryCount; _onRetry = onRetry; _context = context; } public RetryPolicyStateWithCount(int retryCount, Action<Exception, int> onRetry) { Action<Exception, int, Context> onRetry2 = delegate(Exception exception, int i, Context context) { onRetry(exception, i); }; this..ctor(retryCount, onRetry2, null); } public bool CanRetry(Exception ex) { _errorCount++; bool flag = _errorCount <= _retryCount; if (flag) _onRetry(ex, _errorCount, _context); return flag; } } }