public static bool Retry(TimeSpan timeout, TimeSpan interval, Func<bool> action)
{
ArgumentGuard.NotNull(action, nameof(action));
Stopwatch sw = Stopwatch.StartNew();
while (true)
{
try
{
if (action())
{
return true;
}
}
catch
{
}
if (sw.Elapsed > timeout)
{
return false;
}
Thread.Sleep(interval);
}
}