public static bool DoWhileError(Action action, int iterationLimit = 3, int iterationTimeout = 3000) { DoWhileErrorCallbackDelegate exceptionOccuredEvent = delegate { }; //Action<int, Exception, bool> exceptionOccuredEvent = null; return(DoWhileError(action, exceptionOccuredEvent, iterationLimit, iterationTimeout)); }
public static bool DoWhileError(Action action, DoWhileErrorCallbackDelegate exceptionOccuredEvent, //Action<int, Exception, bool> exceptionOccuredEvent, int iterationLimit = 3, int iterationTimeout = 3000) { if (action == null) { return(true); } var iteration = 0; while (true) { try { action(); return(true); } catch (Exception exception) { var cancel = false; var ex = exception; exceptionOccuredEvent?.Invoke(iteration, ex, ref cancel); if (cancel) { break; } } if (iterationLimit > 0) { if (iteration == iterationLimit) { return(false); } else { iteration++; } } Thread.Sleep(iterationTimeout); } return(false); }