29 lines
705 B
C#
29 lines
705 B
C#
![]() |
using System;
|
|||
|
using System.Threading;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace BITKit
|
|||
|
{
|
|||
|
public static partial class TaskHelper
|
|||
|
{
|
|||
|
public static async Task WaitUntil(Func<bool> func)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
await WaitUntil(func, BITApp.CancellationToken);
|
|||
|
}
|
|||
|
catch (OperationCanceledException)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
public static async Task WaitUntil(Func<bool> func, CancellationToken cancelToken)
|
|||
|
{
|
|||
|
while (func is not null && func() is false)
|
|||
|
{
|
|||
|
cancelToken.ThrowIfCancellationRequested();
|
|||
|
await Task.Delay(64);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|