//每一个task执行最多6条 var remainder = length % 6; int i = 0; List<Task> tasks = new List<Task>(); int max; StringBuilder sb = new StringBuilder(); while ((max = i + 6) <= length || (max = i + remainder) <= length) { if (i >= length) { break; } tasks.Add(Task.Run(() => { HandleData(i, max, sb); })); i = max; } Task.WaitAll(tasks.ToArray());
原文:https://www.cnblogs.com/bibi-feiniaoyuan/p/14452432.html