标签:
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); } }
标签:
原文地址:http://www.cnblogs.com/lenmom/p/5685886.html