CSharp - Use NotBuffered option with WithMergeOptions operator

Description

Use NotBuffered option with WithMergeOptions operator

Demo

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
class Program//from   www. ja  va  2 s. co m
{
    static void Main(string[] args)
    {
        IEnumerable<int> results = ParallelEnumerable.Range(0, 10)
            .WithMergeOptions(ParallelMergeOptions.NotBuffered )
            .Select(i => {
                System.Threading.Thread.Sleep(1000);
                return i;
            });
        
        Stopwatch sw = Stopwatch.StartNew();
        
        foreach (int i in results) {
            Console.WriteLine("Value: {0}, Time: {1}", i, sw.ElapsedMilliseconds);
        }
    }
}

Result

Related Topic