C#如何判断线程池中所有的线程是否已经完成之Demo
2018-02-06 09:58
831 查看
start: System.Threading.RegisteredWaitHandle rhw = null; new Action(() => { for (var i = 0; i < 30; i++) { new Action<int>((index) => { System.Threading.Thread.Sleep(1000); Console.WriteLine(System.Threading.Thread.CurrentThread.Name + "执行完毕" + index); }).BeginInvoke(i, null, null); } }).BeginInvoke(null, null); rhw = System.Threading.ThreadPool.RegisterWaitForSingleObject(new System.Threading.AutoResetEvent(false), new System.Threading.WaitOrTimerCallback((obj, b) => { int workerThreads = 0; int maxWordThreads = 0; //int int compleThreads = 0; System.Threading.ThreadPool.GetAvailableThreads(out workerThreads, out compleThreads); System.Threading.ThreadPool.GetMaxThreads(out maxWordThreads, out compleThreads); //Console.WriteLine(workerThreads); //Console.WriteLine(maxWordThreads); //当可用的线数与池程池最大的线程相等时表示线程池中所有的线程已经完成 if (workerThreads == maxWordThreads) { //当执行此方法后CheckThreadPool将不再执行 rhw.Unregister(null); //此处加入所有线程完成后的处理代码 Console.WriteLine("f"); rhw = null; } }), null, 100, false); while (rhw != null) { } System.Threading.Thread.Sleep(10000) ; goto start; Console.WriteLine("finished");
相关文章推荐
- C#如何判断线程池中所有的线程是否已经完成之Demo
- C#如何判断线程池中所有的线程是否已经完成
- [原创]如何判断线程池中所有的线程是否已经完成
- C# C#如何判断线程池中所有的线程是否已经完成,Backgroudworker
- C#如何判断线程池中所有的线程是否已经完成(转)
- C#判断线程池中所有的线程是否已经完成
- Java 如何判断线程池所有任务是否执行完毕
- Java如何判断线程池所有任务是否执行完毕
- Java 如何判断线程池所有任务是否执行完毕
- Java如何判断线程池所有任务是否执行完毕
- Java如何判断线程池所有任务是否执行完毕
- Java如何判断线程池所有任务是否执行完毕
- Java如何判断线程池所有任务是否执行完毕
- 常量,字段,构造方法 调试 ms 源代码 一个C#二维码图片识别的Demo 近期ASP.NET问题汇总及对应的解决办法 c# chart控件柱状图,改变柱子宽度 使用C#创建Windows服务 C#服务端判断客户端socket是否已断开的方法 线程 线程池 Task .NET 单元测试的利剑——模拟框架Moq
- Java 如何判断线程池所有任务是否执行完毕
- Java如何判断线程池所有任务是否执行完毕
- Java如何判断线程池所有任务是否执行完毕
- Java 如何判断线程池所有任务是否执行完毕
- 方法一 Java如何判断线程池所有任务是否执行完毕
- Java 如何判断线程池所有任务是否执行完毕