using System.Threading.Tasks;
public static void Main()
static void CancelParallelLoop()
var cts = new CancellationTokenSource();
cts.Token.ThrowIfCancellationRequested();
cts.Token.Register(() => Console.WriteLine("** token cancelled"));
ParallelLoopResult result =
CancellationToken = cts.Token
Console.WriteLine("loop {0} started", x);
for (int i = 0; i < 100; i++)
Console.WriteLine("loop {0} finished", x);
catch (OperationCanceledException ex)
Console.WriteLine(ex.Message);