MES-ETL/MesETL.Shared/Helper/Extensions.Task.cs
2024-02-10 17:12:26 +08:00

19 lines
501 B
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace MesETL.Shared.Helper;
public static class TaskExtensions
{
public static async Task WaitUntil(Func<bool> condition, int pollDelay = 25, CancellationToken ct = default)
{
try
{
while (!condition())
{
await Task.Delay(pollDelay, ct);
}
}
catch(TaskCanceledException)
{
// CancellationToken激活时Task.Delay通过抛异常来结束停止等待不用管它
}
}
}