Saturday, February 19, 2011

Parallel Programming in .NET 4.0

What is PFX?

PFX- Parallel programming Framework in .NET 4.0 Microsoft Introduced new Library called TPL Tasks Parallel Library. Parallel programming is boarder concept of multithreading. Parallel programming means leveraging multicore or multiprocessor.

image

Why we need to do Parallelism to our code ?

In Recent days we can see that computer CPU speeds are stagnated and adding more cores. so our current programming code wont utilize the all Cores. To speed up and utilize al Cores we need to add Parallel programming code. Even we can use basic System.Threading Namespace to do all Multithreading but its harder to do Data partitioning and collating and thread safety. But it easy to do with Microsoft new TPL library which comes with .NET Framework 4.0

One of the  main feature in .NET Framework is TPL framework Libraries.  TPL – Task Parallel Library . This Library make it easier for developers to write Parallel programs that can run on multi-core Machines. In this blog post I am going to show you how to write Parallel /Asynchronous  programming.

First  let us look at the  TASK Class  this class lives in System.Threading.Tasks

image

Here is simple programs using Task class.

TASK:

image

image

ContinueWith:

Suppose we want to execute some task one after another , I mean continues task we can use  ContinueWith  method 

image

Here is my extension method to print IEnumerable<T>

image

 

Nandri(Thanks)

SreenivasaRagavan.

No comments: