[.net 多线程]ThreadPool

 CancellationTokenSource tocken = new CancellationTokenSource();
ThreadPool.QueueUserWorkItem(param => {
Console.WriteLine($"当前线程【{Thread.CurrentThread.ManagedThreadId}】");
Thread.Sleep();
Console.WriteLine($"当前线程【{Thread.CurrentThread.ManagedThreadId}】退出");
}, tocken);

两种出发模式:定时8s出发,事件触发器出发(autoresetevent)

 AutoResetEvent evt = new AutoResetEvent(false);
ThreadPool.RegisterWaitForSingleObject(evt, (state, isOut) =>
{
CancellationTokenSource token = (CancellationTokenSource)state;
if (tocken.IsCancellationRequested)
{
Console.WriteLine("退出RWFS");
return;
}
Console.WriteLine("RWFS...");
}, tocken, , false);
上一篇:Selenium 工作原理


下一篇:jQuery中操作属性的方法attr与prop的区别