Elight.Utility/Threads/WaitUtil.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Elight.Utility.Threads
{
/// <summary>
/// 等待变量加载工具类
/// </summary>
public class WaitUtil
{
#region Wait 等待变量加载完成
/// <summary>
/// 等待变量加载完成
/// </summary>
/// <param name="func">在此方法中初始化变量</param>
/// <param name="seconds">超时时间(单位:秒)(超时后停止等待)</param>
public static void Wait(Func<ICollection> func, int seconds = 20)
{
int interval = 500;
int maxTryCount = seconds * 1000 / interval;
int tryCount = 0;
ICollection obj = func();
while (IsNullOrEmpty(obj) && tryCount++ < maxTryCount)
{
Thread.Sleep(interval);
obj = func();
Console.WriteLine("等待变量初始化");
//LogUtil.Log();
}
//LogUtil.Log("变量初始化完成");
}
#endregion
#region Wait 等待变量加载完成
/// <summary>
/// 等待变量加载完成
/// </summary>
/// <param name="func">在此方法中初始化变量</param>
/// <param name="seconds">超时时间(单位:秒)(超时后停止等待)</param>
public static void Wait(Func<object> func, int seconds = 20)
{
int interval = 500;
int maxTryCount = seconds * 1000 / interval;
int tryCount = 0;
object obj = func();
while (obj == null && tryCount++ < maxTryCount)
{
Thread.Sleep(interval);
obj = func();
Console.WriteLine("等待变量初始化");
}
Console.WriteLine("变量初始化完成");
}
#endregion
后面还有 33 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。