我试图使用下面的函数不返回true/false,除非布尔函数arg返回true或超时到期.在当前状态下,如果布尔函数arg返回false,则立即返回false而不是循环并重试X更多毫秒.
public delegate bool BooleanFunction ();
public static async Task<bool> Wait(uint Milliseconds, BooleanFunction Function)
{
var StartTime = Environment.TickCount;
do
{
if (Function())
{
return true;
}
Thread.Yield();
}
while (Environment.TickCount < StartTime + Milliseconds);
return false;
}
Run Code Online (Sandbox Code Playgroud)