How to execute tons of tasks parallelly with TPL method?
2015-11-29 17:12
603 查看
List<Task> taskList = new List<Task>(); // string currentNoStr = null; cannot define at here, we should define the copy in for loop, this is a .NET FW bug for 4.0/4.5 // I am not sure whether this issue is fixed in latest version, below is the workaround for (int currentNo = startPhaseNo; currentNo <= endPhaseNo; currentNo++) { string currentNoStr = currentNo.ToString(); taskList.Add(Task.Run(() => { string result = GetLotteryByPhase(currentNoStr); if (!string.IsNullOrEmpty(result)) { resultDict.Add(currentNoStr, result); } })); if (currentNo % 1000 >= 155) { currentNo /= 1000; currentNo++; currentNo *= 1000; continue; } } await Task.WhenAll(taskList); return resultDict;
相关文章推荐
- PHP不使用递归的无限级分类
- 简单配置局域网FTP
- 在eclipse中用thinkphph框架
- PHP 验证日期格式
- PHP接收json,并将接收数据插入数据库
- php判断变量类型常用方法
- thinkphp笔记-创建数据2
- PHP - 解决中文乱码问题
- 最好用的PHP数据库操作类-ezSQL
- thinkphp笔记-创建数据
- PHP后期静态绑定的功能
- PHP后期静态绑定的功能
- thinkphp笔记-访问数据
- php魔术方法__autoload()
- PHP可变函数学习小结
- PHP可变变量学习小结
- 解决PHP显示Warning和Notice等问题
- hibernate的3种继承映射关系总结——TPH,TPS,TPC
- ContentProvider
- ThinkPHP引入文件的标签