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 % 1000 >= 155)
                {
                    currentNo /= 1000;
                    currentNo++;
                    currentNo *= 1000;
                    continue;
                }
            }
            await Task.WhenAll(taskList);
            return resultDict;
时间: 2024-12-23 02:53:03

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 using non blocking calls to the data layer is a great way to increase the scalability of your system. Performing a task asynchronously frees up the worke

wesome-android

awesome-android Introduction android libs from github System requirements Android Notice If the lib is no longer being maintained,please do not add it here. How To Contribute Step 1. Add a Item as follows: **Library Name**[one space]Short Description

GitHub中常用开源库

awesome-android Introduction android libs from github System requirements Android Notice If the lib is no longer being maintained,please do not add it here. Libs Table of contents Framework EventBus Orm Image Loading Animations Network Widget Materia

github中的常用库

awesome-android android libs from github Download ZIP Download TAR View On GitHub This project is maintained bysnowdream awesome-android Introduction android libs from github System requirements Android Notice If the lib is no longer being maintained

在Oracle中使用命令crs_stat -t,输出结果里资源名称后缀的含义

[[email protected]:/]$crs_stat -tName           Type           Target    State     Host        ------------------------------------------------------------ora....TA01.dg ora....up.type ONLINE    ONLINE    udevasm     ora....TA02.dg ora....up.type ONL

openstack 调用API 实现云主机的IO 控制,CGroup 策略

# vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright (c) 2011 X.commerce, a business unit of eBay Inc. # Copyright 2010 United States Government as represented by the # Administrator of the National Aeronautics and Space Administration. # All Righ

Oracle 11g RAC oc4j/gsd Offline

Oracle 11g RAC中,发现oc4j以及gsd服务都处于offline状态,这是Oracle 11g RAC默认情形.即便如此,并不影响数据库的使用,因为 oc4j 是用于WLM 的一个资源, WLM在 11.2.0.2 才可用.GSD则是用于支持dbca,srvctl,oem等的交互工具.本文描述将这两个服务切换到online. [python] view plain copy print? 1.环境 [[email protected] ~]# cat /etc/issue Ente

Java基础之-ExecutorService

翻译javadoc系列文章之:ExecutorService /** * An {@link Executor} that provides methods to manage termination and * methods that can produce a {@link Future} for tracking progress of * one or more asynchronous tasks. * * <p> An <tt>ExecutorService</

线程池的原理与实现

java中的线程池框架为Executors,但是这里我们将自己实现简单的线程池,主要目的是理解它的原理. 线程池主要由两个部分组成: (1)线程数组,用于执行任务. (2)任务队列. 下面的两个实现都是按照这种思路来做的. 一.简单的线程池,有点问题 package com.chuiyuan.utils; import java.util.LinkedList; /** * Created by chuiyuan on 2/21/16. * start: * create a new threa