public static void WaitUntilSuccess(Action action, ListSleeper sleeper, int maxWaitSeconds = 300) { WaitUntil(() => { try { action(); return(true); } catch { return(false); } }, sleeper, maxWaitSeconds); }
public static void WaitUntil(Func <bool> matchFunction, ListSleeper sleeper, int maxWaitSeconds = 300) { if (maxWaitSeconds < 0) { throw new ArgumentOutOfRangeException("maxWaitSeconds"); } var maxTime = TimeSpan.FromSeconds(maxWaitSeconds); var endTime = DateTime.Now + maxTime; while (DateTime.Now < endTime) { if (matchFunction()) { return; } sleeper.Sleep(); } throw new TimeoutException(string.Format("Wait condition was not satisfied for {0} seconds", maxWaitSeconds)); }