Parallel For methods in .net 4.0 System.Threading.Tasks.Parallel static class

.Net 4.0 supports parallelism by using System.Threading.Tasks.Parallel static class. This class is having methods like Parallel.For, Parallel.ForEach etc. Data will be partitioned in to different threads using these methods; we don't need to write explicit implementation of thread execution. So the CPU usage and execution time will greatly reduce.

Here is one Example using the Parallel.For

System.Threading.Tasks.Parallel.For(0, 30000000, delegate(int i) {

            //do something here

         });

Here is the conventional for loop which is a sequential process

for (int  i = 0; i < 10000000; i++) {

         //do something here

        }


-Shinu

Ebook Download
View all
My Ideas
Read by 2 people
Download Now!
Learn
View all