Parallel Class

Another abstraction of threads that is new with .NET 4 is the Parallel class. This class defi nes static methods for a parallel for and foreach . With the language defi ned for for and foreach , the loop is run from one thread. The Parallel class uses multiple tasks and, thus, multiple threads for this job.
 
While the Parallel.For() and Parallel.ForEach() methods invoke the same method several times, Parallel.Invoke() allows invoking different methods concurrently.

Example

    class Program
    {
        static int N = 1000;

        static void TestMethod()
        {
            // Using a named method.
            Parallel.For(0, N, Method2);

            // Using an anonymous method.
            Parallel.For(0, N, delegate(int i)
            {
                // Do Work.
            });

            // Using a lambda expression.
            Parallel.For(0, N, i =>
            {
                // Do Work.
            });
        }

        static void Method2(int i)
        {
            // Do work.
        }
    }