NetAutoGUI/EnumerableExtensions.cs
(完整代码) 1KBusing System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
namespace NetAutoGUI
{
public static class EnumerableExtensions
{
public static TSource WaitSingle<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate, double timeoutSeconds = 2)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
TSource? result;
while ((result = source.SingleOrDefault(predicate)) == null)
{
if (stopwatch.ElapsedMilliseconds > timeoutSeconds * 1000)
{
throw new TimeoutException("WaitSingle timeout");
}
Thread.Sleep(50);
}
return result;
}
public static TSource WaitFirst<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate, double timeoutSeconds = 2)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
TSource? result;
while ((result = source.FirstOrDefault(predicate)) == null)
{
if (stopwatch.ElapsedMilliseconds > timeoutSeconds * 1000)
{
throw new TimeoutException("WaitSingle timeout");
}
Thread.Sleep(50);
}
return result;
}
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。