public class Retry { // Methods public static void Do(Action action, int timeoutMS = 50, int retryCount = 3) { Do<object>(delegate { action(); return null; }, timeoutMS, retryCount); } public static ResultType Do<ResultType>(Func<ResultType> action, int timeoutMS = 50, int retryCount = 3) { List<Exception> innerExceptions = new List<Exception>(); for (int i = 0; i < retryCount; i++) { try { return action(); } catch (Exception exception) { innerExceptions.Add(exception); Thread.Sleep(timeoutMS); } } throw new AggregateException(innerExceptions); } }