mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
34 lines
923 B
C#
34 lines
923 B
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Remotely.Shared.Utilities
|
|
{
|
|
public static class TaskHelper
|
|
{
|
|
public static bool DelayUntil(Func<bool> condition, TimeSpan timeout, int pollingMs = 10)
|
|
{
|
|
var sw = Stopwatch.StartNew();
|
|
while (!condition() && sw.Elapsed < timeout)
|
|
{
|
|
Thread.Sleep(pollingMs);
|
|
}
|
|
return condition();
|
|
}
|
|
|
|
public static Task<bool> DelayUntilAsync(Func<bool> condition, TimeSpan timeout, int pollingMs = 10)
|
|
{
|
|
return Task.Run(() =>
|
|
{
|
|
var sw = Stopwatch.StartNew();
|
|
while (!condition() && sw.Elapsed < timeout)
|
|
{
|
|
Thread.Sleep(pollingMs);
|
|
}
|
|
return condition();
|
|
});
|
|
}
|
|
}
|
|
}
|