Parallel Compting in C# 4.0

Anup1252000
Posted by in C# category on for Beginner level | Views : 17044 red flag
Rating: 5 out of 5  
 1 vote(s)

In this article, you will see how to use Parallel Computing in c#


 Download source code for Parallel Compting in C# 4.0

Introduction

Now days, hardware supports 2 core and 4 core processor that help multiple thread to be executed at a same time.
By using the advanced hardware, you can distribute your work across multiple processors simultaneously.

Architecture

Here is the Architecture of Parallel Computing. I took this diagram from the MSDN.

Reference: MSDN

Advantage and disadvantage of using Parallel computing:

Advantage

  • Suppose if you are running long method then you can send that particular method in the thread and you don’t
     need to wait until that method is executed.
  • Performance of the application is very fast.

Disadvantage

  • It’s a fire and forgets kind of mechanism. We don’t know when we get the result back. As per my knowledge its better to use in a dropdownlist. For example: In the long filling info such as Signup.

Here in this article I am working on VS2008. You can download Parallel Computing for VS 2008 here. Here in this article I am concentrating on PLINQ. For better understanding you first need to understand Parallel Enumerable Operators: 

Code Part:

In some of the cases I have used LINQ to SQL. Diagram will look like this

Here I am working on only one table called employee. First let’s work on simple query. Here we are using AsParallel() operator.

Here we will see how to use AsOrdered() operator.

Here we will see how to use AsSequential() operator.

Now lets understand, how to use Exceptional Handling in PLINQ. To Catch the exception in PLINQ we need to use AggregateException.

Here we will see how to cancel the excution using WithCancellation() operator.

Hope this article would have given a good insight of the basics of the Parallel computing. Keep learning and reading my forthcoming articles.

 

Reference

http://msdn.microsoft.com/en-us/library/dd460693.aspx

Page copy protected against web site content infringement by Copyscape

About the Author

Anup1252000
Full Name: anup hosur
Member Level:
Member Status: Member
Member Since: 8/1/2009 2:37:23 AM
Country: India
https://wordpress.com/pages/anuphosur.wordpress.com
https://wordpress.com/pages/anuphosur.wordpress.com
He is the .net developer with around 8 years of experience in technologies like c#, WCF, WPF and Asp.net. https://wordpress.com/pages/anuphosur.wordpress.com

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)