• 经典多线程任务分发合并模型


    最近写了个关于多线程的分发合并代码:

     1 public static string GetCSVStringFromFacotry(int MaximumCurveNumber,IEmerable<IData> revertEligible)
     2     {
     3         int currenttotalNumverOfCurve = revertEligible.Count();
     4         List<Task> tasks = new List<Task>();
     5         int startIndex = 0;
     6         while (currenttotalNumverOfCurve > 0)
     7         {
     8             List<IData> currentExecuteCurveList = new List<IData>();
     9             for (int i = startIndex; i < startIndex + MaximumCurveNumber; i++)
    10             {
    11                 if(revertEligible.Count() > i)
    12                     currentExecuteCurveList.Add(revertEligible.ElementAt(i));
    13             }
    14 
    15             tasks.Add(Task.Factory.StartNew
    16                 (
    17                 () =>
    18                 {
    19                     string content = GetOneTimeCSVStringFromFacotry(currentExecuteCurveList);
    20                     //Remove header
    21                     lock (result)
    22                     {
    23                         if (!string.IsNullOrWhiteSpace(result))
    24                         {
    25                             //Remove header
    26                             content = RemoveCSVHeader(content);
    27                         }
    28                         result += content;
    29                     }
    30                 }
    31             ));
    32             currenttotalNumverOfCurve -= MaximumCurveNumber;
    33             startIndex += MaximumCurveNumber;
    34         }
    35         try
    36         {
    37             Task.WaitAll(tasks.ToArray());
    38         }
    39         catch (AggregateException ae)
    40         {
    41             foreach (var innerException in ae.InnerExceptions)
    42             {
    43                 log.Error("Exception in GetCSVStringFromFacotry", innerException);
    44             }
    45         }
    46         return result;
    47     }
  • 相关阅读:
    header
    panel----单个基础版
    vue-demo
    js不同类型变量比较
    reset.css
    关于各个浏览器的兼容问题
    git
    AMD与CMD区别
    喜欢前端的看过来哦
    js中数组去重的几种方法
  • 原文地址:https://www.cnblogs.com/xiaomaogong/p/3488963.html
Copyright © 2020-2023  润新知