Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you can use Rx Extensions, this would be my favorite solution.</p> <pre><code>namespace ConsoleApplication2 { using System; using System.Collections.Generic; using System.Linq; using System.Reactive.Linq; internal class Program { #region Constants private const int chunkSize = 50; #endregion #region Methods private static void Main(string[] args) { List&lt;string&gt; bigList = Enumerable.Range(0, 99).Select(s =&gt; s.ToString()).ToList(); bigList.ToObservable().Buffer(chunkSize).Subscribe( chunk =&gt; { foreach (string s in chunk) { Console.WriteLine(s); } Console.WriteLine(String.Empty.PadRight(80, '-')); }); } #endregion } } </code></pre> <p>Combined with Parallel Extensions Extras</p> <pre><code>namespace ConsoleApplication2 { using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Reactive.Linq; using System.Threading; using System.Threading.Tasks; using System.Threading.Tasks.Schedulers; internal class Program { #region Constants private const int ChunkSize = 50; #endregion #region Methods private static void Main(string[] args) { var cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = cancellationTokenSource.Token; var workStealingTaskScheduler = new WorkStealingTaskScheduler(Environment.ProcessorCount - 1); var bag = new ConcurrentBag&lt;Task&gt;(); IEnumerable&lt;string&gt; bigList = Enumerable.Range(0, 10000).Select(s =&gt; s.ToString()); bigList.ToObservable().Buffer(ChunkSize).Subscribe( chunk =&gt; bag.Add( Task.Factory.StartNew( () =&gt; { foreach (string s in chunk) { Console.WriteLine(s); } Console.WriteLine(String.Empty.PadRight(80, '-')); }, cancellationToken, TaskCreationOptions.None, workStealingTaskScheduler))); Task.WaitAll(bag.ToArray()); } #endregion } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload