/// <summary> /// 任务 /// </summary> /// <param name="mode">枚举 同步、异步</param> /// <param name="trigger">任务适配器 <see cref="RetryAdapter"/></param> /// <param name="callback">任务委托</param> /// <param name="errorCallback">异常信息委托</param> public static void Run(RetryMode mode, RetryAdapter trigger, Action <int> callback, Func <int, Exception, bool> errorCallback = null) { switch (mode) { case RetryMode.Async: AsyncExecute(() => { Run(RetryMode.Sync, trigger, callback, errorCallback); }); break; default: int current = 1; while (current <= trigger.MaxRun) { if (ActionExecute(current, callback, errorCallback)) { break; } else { if (current <= trigger.MaxRun) { System.Threading.Thread.Sleep(trigger.Wait); } current++; } } break; } }
/// <summary> /// 任务 /// </summary> /// <param name="mode">枚举 同步、异步</param> /// <param name="callback">任务委托</param> /// <param name="errorCallback">异常信息委托</param> public static void Run(RetryMode mode, Action <int> callback, Func <int, Exception, bool> errorCallback = null) { Run(mode, RetryAdapter.Create().MaxRuns(3), callback, errorCallback); }