How to execute tons of tasks parallelly with TPL method?
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 % >= )
{
currentNo /= ;
currentNo++;
currentNo *= ;
continue;
}
}
await Task.WhenAll(taskList);
return resultDict;
How to execute tons of tasks parallelly with TPL method?的更多相关文章
- Why you should use async tasks in .NET 4.5 and Entity Framework 6
Improve response times and handle more users with parallel processing Building a web application usi ...
- [转]How to: Execute Oracle Stored Procedures Returning RefCursors
本文转自:http://www.telerik.com/help/openaccess-orm/openaccess-tasks-oracle-execute-sp-result-set.html I ...
- wesome-android
awesome-android Introduction android libs from github System requirements Android Notice If the lib ...
- Windows Service--Write a Better Windows Service
原文地址: http://visualstudiomagazine.com/Articles/2005/10/01/Write-a-Better-Windows-Service.aspx?Page=1 ...
- java多线程系类:JUC线程池:03之线程池原理(二)(转)
概要 在前面一章"Java多线程系列--"JUC线程池"02之 线程池原理(一)"中介绍了线程池的数据结构,本章会通过分析线程池的源码,对线程池进行说明.内容包 ...
- Don't Block on Async Code【转】
http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html This is a problem that is brough ...
- Java多线程系列--“JUC线程池”03之 线程池原理(二)
概要 在前面一章"Java多线程系列--“JUC线程池”02之 线程池原理(一)"中介绍了线程池的数据结构,本章会通过分析线程池的源码,对线程池进行说明.内容包括:线程池示例参考代 ...
- Sharepoint学习笔记—习题系列--70-576习题解析 -(Q16-Q18)
Question 16 You are designing a SharePoint 2010 solution to manage statements of work. You need to d ...
- Java基础之-ExecutorService
翻译javadoc系列文章之:ExecutorService /** * An {@link Executor} that provides methods to manage termination ...
随机推荐
- JS弹出下载对话框以及实现常见文件类型的下载
写在前面 JS要实现下载功能,一般都是这么几个过程:生成下载的URL,动态创建一个A标签,并将其href指向生成的URL,然后触发A标签的单击事件,这样就会弹出下载对话框,从而实现了一个下载的功能. ...
- nyoj_3:多边形重心问题(计算几何)
基础的计算几何 多边形的n个顶点按*时针方向给出 由任意n边形可分解为n-2个三角形,各三角形面积面积与重心易得,故有各三角形的面积及重心 用重心公式可求得多边形的面积与重心 题目链接: http:/ ...
- Docker for windows10 配置镜像加速
windows玩docker的时候,经常碰到这种问题: Error response from daemon: Get https://registry-1.docker.io/v2/: net/ht ...
- Go语言学习笔记(四)结构体struct & 接口Interface & 反射
加 Golang学习 QQ群共同学习进步成家立业工作 ^-^ 群号:96933959 结构体struct struct 用来自定义复杂数据结构,可以包含多个字段(属性),可以嵌套: go中的struc ...
- 有关struts中DispatchAction的用法小结
今天刚刚看了DispatchAction觉得这个东西有点意思,所以就写点东西,通过它的名字我想应该可以明白它的作用了,用于分发的Action,主要的好处是把一些功能类似的Action放到一个Ac ...
- 【Django】django 的request和response(转)
当请求一个页面时,Django 把请求的 metadata 数据包装成一个 HttpRequest 对象,然后 Django 加载合适的 view 方法,把这个 HttpRequest 对象作为第一个 ...
- 一次浴火重生的MySQL优化(EXPLAIN命令详解)
一直对SQL优化的技能心存无限的向往,之前面试的时候有很多面试官都会来一句,你会优化吗?我说我不太会,这时可能很多人就会有点儿说法了,比如会说不要使用通配符*去检索表.给常常使用的列建立索引.还有创建 ...
- 连续子序列最大和的O(NlogN)算法
对于一个数组,例如:int[] a = {4,-3,5,-2,-1,2,6,-2}找出一个连续子序列,对于任意的i和j,使得a[i]+a[i+1]+a[i+2]+.......+a[j]他的和是所有子 ...
- ASP.NET Core 源码学习之 Logging[3]:Logger
上一章,我们介绍了日志的配置,在熟悉了配置之后,自然是要了解一下在应用程序中如何使用,而本章则从最基本的使用开始,逐步去了解去源码. LoggerFactory 我们可以在构造函数中注入 ILogge ...
- Maven导出Project依赖的jar包
Maven导出Project依赖的jar包 从Maven仓库中导出jar包: mvn dependency:copy-dependencies 会导出到Project的targed/dependenc ...