namespace Hotline.Share.Tools; /// /// 重试操作辅助类 /// public static class RetryHelper { /// /// 重试 /// /// 重试方法 /// 重试次数 (1 与 100 之间的整数) /// 重试等待毫秒 /// 是否执行成功 public static bool Retry(Func func, int times, int millisecond = 0) { if (times <= 1 && times >= 100) { throw new ArgumentOutOfRangeException("times 参数有误。只能是介于 1 与 100(包含1和100)之间的整数。"); } while (times > 0) { if (func()) { return true; } times--; if (millisecond > 0) { Thread.Sleep(millisecond); } } return false; } }