public static bool RetryCallUntilBooleanReturn(bool bUntil, string strInput, RetryCallback cb, int cMaxTimes = RETRY_MAX_COUNT, int msSleepTime = RETRY_SLEEP_MILLISECONDS) { bool bFlag = !bUntil; for (int iRetry = 0; iRetry < cMaxTimes; iRetry++) { bFlag = cb(strInput); if (bFlag == bUntil) { break; } System.Threading.Thread.Sleep(msSleepTime); } return(bFlag); }
/// <summary> /// Creates wrapper delegate around "RetryCallback". Can be used for loggin or debug purpose. /// Please note that this delegate should be passed first when combine with RetryStrategyDelegate. /// </summary> /// <param name="callback">User callback.</param> /// <returns>Retry strategy delegate.</returns> public static RetryStrategy CreateCallbackRetryStrategy(RetryCallback callback) { return((int attemptCount, Exception lastException, out TimeSpan neededDelay) => { neededDelay = TimeSpan.Zero; try { callback(attemptCount, lastException); } catch (Exception) { // Ignored. } return false; }); }