Elight.Utility/Threads/TaskSchedulerEx.cs
(开头部分) 7KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Elight.Utility.Threads
{
/// <summary>
/// TaskScheduler扩展
/// 每个实例都是独立线程池
/// </summary>
public class TaskSchedulerEx : TaskScheduler, IDisposable
{
#region 外部方法
[DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]
public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
#endregion
#region 变量属性事件
private ConcurrentQueue<Task> _tasks = new ConcurrentQueue<Task>();
private int _coreThreadCount = 0;
private int _maxThreadCount = 0;
private int _auxiliaryThreadTimeOut = 20000; //辅助线程释放时间
private int _activeThreadCount = 0;
private System.Timers.Timer _timer;
private object _lockCreateTimer = new object();
private bool _run = true;
private Semaphore _sem = null;
private int _semMaxCount = int.MaxValue; //可以同时授予的信号量的最大请求数
private int _semCount = 0; //可用信号量请求数
private int _runCount = 0; //正在执行的和等待执行的任务数量
/// <summary>
/// 活跃线程数
/// </summary>
public int ActiveThreadCount
{
get { return _activeThreadCount; }
}
/// <summary>
/// 核心线程数
/// </summary>
public int CoreThreadCount
{
get { return _coreThreadCount; }
}
/// <summary>
/// 最大线程数
/// </summary>
public int MaxThreadCount
{
get { return _maxThreadCount; }
}
#endregion
后面还有 179 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。