/// <summary> /// Invoke operation async /// </summary> /// <param name="operation">the operation async</param> /// <param name="onException">the exception handler async</param> /// <param name="retryManager">the retry manager</param> /// <returns>the operation result</returns> public async static Task <T> InvokeOperationAsync(OperationDelegateAsync operation, HandleExceptionDelegateAsync onException, RetryManager retryManager) { Exception lastException = null; while (true) { try { return(await operation().ConfigureAwait(false)); } catch (Exception e) { lastException = e; } await onException(lastException, retryManager).ConfigureAwait(false); if (retryManager.HasAttemptsLeft) { await retryManager.AwaitForNextAttempt().ConfigureAwait(false); } else { break; } } throw lastException; }