Zawód.Programista.NET() Profession, passion, appointment – notes about my adventures with. net

12Aug/100

Parallel.For – Multithreading has never been so easy

In the last version C# there is the possibility zrównoleglenia calculations in a very simple way. Loop:

for (int n = 0; n < 8; n++)
{
   Console.WriteLine("Normal - iteracja {0} wątek {1}", n,
     Thread.CurrentThread.ManagedThreadId);
}

can be replaced by the following structure:

Parallel.For(08, i =>
{
   Console.WriteLine("Parallel - iteracja {0} wątek {1}", i,
      Thread.CurrentThread.ManagedThreadId);
});