not to say extra words,let`s start the code.
pasted below:
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace paraldemo { class Program { static void Main(string[] args) { var watch = Stopwatch.StartNew(); watch.Start(); var a = 2; var c = 0; String[] names = new string[] { "a", "b" }; Parallel.ForEach(names, d => { Console.Write("paraeel:" + d); }); Parallel.For(1, 4, b => { c += b; }); Parallel.Invoke(() => { Console.WriteLine(1); }, () => Console.WriteLine(2)); Console.WriteLine(c); watch.Stop(); Console.WriteLine(watch.ElapsedMilliseconds); var task1 = Task.Factory.StartNew(() => { Console.WriteLine("test task factory"); }); task1.Wait(2000); var task2 = Task.Factory.StartNew(e => Console.WriteLine("2" + e), c); Task.WaitAll(task1, task2); Parallel.Invoke(() => Console.WriteLine(1)); Task.Factory.StartNew(() => Console.WriteLine(2), new CancellationTokenSource().Token); Console.ReadKey(); } } }
PLinq
from a in list.AsParallel