标签:manage setevent 事件 两种 ... als reset single leo
1 CancellationTokenSource tocken = new CancellationTokenSource(); 2 ThreadPool.QueueUserWorkItem(param => { 3 Console.WriteLine($"当前线程【{Thread.CurrentThread.ManagedThreadId}】"); 4 Thread.Sleep(1000); 5 Console.WriteLine($"当前线程【{Thread.CurrentThread.ManagedThreadId}】退出"); 6 }, tocken);
两种出发模式:定时8s出发,事件触发器出发(autoresetevent)
1 AutoResetEvent evt = new AutoResetEvent(false); 2 ThreadPool.RegisterWaitForSingleObject(evt, (state, isOut) => 3 { 4 CancellationTokenSource token = (CancellationTokenSource)state; 5 if (tocken.IsCancellationRequested) 6 { 7 Console.WriteLine("退出RWFS"); 8 return; 9 } 10 Console.WriteLine("RWFS..."); 11 }, tocken, 8000, false);
标签:manage setevent 事件 两种 ... als reset single leo
原文地址:https://www.cnblogs.com/deepminer/p/9074606.html