Smart Thread Pool
来源:互联网 发布:马克笔淘宝网 编辑:程序博客网 时间:2024/06/04 23:10
demo:
https://www.codeproject.com/Articles/7933/Smart-Thread-Pool#SimpleExample
// 创建一个线程池SmartThreadPool smartThreadPool = new SmartThreadPool(); // 执行任务smartThreadPool.QueueWorkItem(() =>{ Console.WriteLine("Hello World!");});
// 创建一个线程池SmartThreadPool smartThreadPool = new SmartThreadPool();// 执行任务var result = smartThreadPool.QueueWorkItem(() =>{ var sum = 0; for (var i = 0; i < 10; i++) sum += i; return sum;});// 输出计算结果Console.WriteLine(result.Result);
等待多个任务完成
// 创建一个线程池SmartThreadPool smartThreadPool = new SmartThreadPool();// 执行任务var result1 = smartThreadPool.QueueWorkItem(() =>{ //模拟计算较长时间 Thread.Sleep(5000); return 3;});var result2 = smartThreadPool.QueueWorkItem(() =>{ //模拟计算较长时间 Thread.Sleep(3000); return 5;});bool success = SmartThreadPool.WaitAll( new IWorkItemResult[] { result1, result2 });if (success){ // 输出结果 Console.WriteLine(result1.Result); Console.WriteLine(result2.Result);}
转载于:
https://www.codeproject.com/Articles/7933/Smart-Thread-Pool
http://blog.csdn.net/greystar/article/details/1766363
http://www.lingdonge.com/marketing/seo/37.html
阅读全文
0 0
- Smart Thread Pool
- Smart Thread Pool 介绍
- SMART THREAD POOL
- Smart Thread Pool
- Smart Thread Pool
- Smart Thread Pool 介绍
- Smart Thread Pool
- smart thread pool 【1】简单的使用
- Smart Thread Pool By Ami Bar A smart Thread Pool implementation in .NET.
- Thread Pool
- Thread Pool
- Thread Pool
- thread pool
- thread pool
- thread pool
- thread pool
- Thread Pool
- thread pool
- 用几条shell命令快速去重10G数据
- redis命令大全(一)
- json和pickle的序列化与反序列化
- Qt浅谈之一:内存泄露(总结)
- 计算机体系结构
- Smart Thread Pool
- excel 转pdf html 图片显示问题
- [book]《失控》
- Object类和String类中常用的方法
- DVRRDK sd启动卡制作
- Spring配置数据源的三种方式 (dbcp,c3p0,jndi)
- Linux文件权限管理
- DeepMind星际争霸2开源机器学习平台
- Centos6.8下搭建SVN服务器