Tutorial :How to write .NET applications that utilize multi-core processors


As multi-core processors become more and more popular, I think it would be wise for me to become familiar with how to write code to take advantage of them. I am a .NET developer, and am not sure where to begin (seriously, I have no clue where to start). Any suggestions?


Multi-core programming is essentially multi-threaded programming. As long as your application is multi-threaded, the operating system will determine which core to run which thread on.

So then, your real question should be, what kind of applications would benefit from being multi-threaded? Think of such an application, then instantiate multiple threads to solve equal portions of the problem.


The best way to start is to grab the latest CTP of the parrallel extensions framework and start plowing through their sample code.


Read up on the asynchronous programming model that .NET uses. Study the BeginXXX and EnxXXX paradigm that allows delegates to execute in the threadpool.

The Stream classes all have BeingXXX, EndXXX methods (eg BeginRead, EndRead) that allow you to do asynchronous IO. If you're working on something that heavily IO based you'll want to use these methods to increase parallelism.


I don't recommend books very often anymore, but Joe Duffy's Concurrent Programming on Windows is simply irreplaceable.


Look for info on the .net 4.0. It will be adding different constructs for it.


Like JaredPar said the Parallel Extensions are pretty good. I played with them a bit and they are easy to use and add performance.

The constructs I liked a lot were Parallel.ForEach() and PLinq.

Parallel.ForEach is similar to the ForEach(delegate) function that you have in DotNet 2.0 collections. It takes an action delegate and runs it in parallel.

Plinq allows you to execute any normal Linq query in a parallel fashion by adding .AsParallel() to the end of the query.

Check out the links Jared posted for more info.


This might make a good starting place.


Simply separating your project into various threads specialized to do a particular function will let you take advantage of multiple cores. The OS handles scheduling the different threads to the most available processor core.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »