using System.Threading.Tasks;
using System.Collections.Concurrent;
using System.Collections.Generic;
public static void Main()
var partitioner = Partitioner.Create(YieldedNumbers());
partitioner.AsParallel(),
var threadId = Thread.CurrentThread.ManagedThreadId;
Console.WriteLine($"{threadId} run at {DateTime.Now}");
Console.WriteLine("Done!");
public static IEnumerable<int> YieldedNumbers()
Random rnd = new Random();
int lastKnownThread = Thread.CurrentThread.ManagedThreadId;
int detectedSwitches = 0;
for (int i = 0; i < 100; i++)
int currentThread = Thread.CurrentThread.ManagedThreadId;
if (lastKnownThread != currentThread)
var st = $"{detectedSwitches}: Last known thread ({lastKnownThread}) is not the same as the current thread ({currentThread}).";
lastKnownThread = currentThread;
yield return rnd.Next(10,150);