Remotely/Shared/Helpers/TaskHelper.cs
2021-07-29 07:56:01 -07:00

22 lines
547 B
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
namespace Remotely.Shared.Helpers
{
public static class TaskHelper
{
public static async Task<bool> DelayUntil(Func<bool> condition, TimeSpan timeout, int pollingMs = 10)
{
var sw = Stopwatch.StartNew();
while (!condition() && sw.Elapsed < timeout)
{
await Task.Delay(pollingMs);
}
return condition();
}
}
}