Sunday, February 27, 2011

AggregateException In Parallel Programming

AggregateException which can contain one or more exceptions. Suppose when you have multiple threads of execution each of the threads could throw and exception as a result .NET Framework “bundle” all of these exceptions which occurred in the parallel operations into one exception which is passed (thrown) back to the caller. Acting as a container for all exceptions generated in a function is the function which the AggregateException Class performs.

To Understand any new concept its better to show in an action with Example.

image

image

Nandri(Thanks)

Sreenivasaragavan

Friday, February 25, 2011

Installing Windows-7 Service Pack 1

Here are the steps to install Windows 7 Service pack 1.  First you need to download System Update Readiness Tool for Windows 7  either 32 bit or b4bit based on what version of windows you installed on your Machine. Here is the link where you can download the above mentioned tool.

image

http://www.microsoft.com/DOWNLOADS/en/details.aspx?FamilyId=914fbc5b-1fba-4bae-a7c3-d2c47c6fcffc&displaylang=en

why this tool needed?

This tool is being offered because an inconsistency was found in the Windows servicing store which may prevent the successful installation of future updates, service packs, and software. This tool checks your computer for such inconsistencies and tries to resolve issues if found.

image

image

image

Nandri(Thanks)

Sreenivasa Ragavan

Saturday, February 19, 2011

Parallel.For and Parallel.ForEach in .NET 4.0

Basically Parallel.For and Parallel.ForEach is very similar to For and ForEach except that  Paralle.For and ForEach use Multiple threads to execute different iterations of the loop body.  Using Parallel loops are very good way to  speed of the multicore machines.

image

when we execute the above code. here is the result .

image

Nandri(Thanks)

SreenivasaRagavan.

Parallel Programming .NET 4.0 IV–Using Task.Factory.FromAsync convert Task to asynchronous Method.

In this blog post we are going to see how we can covert asynchronous method call to Task by using Task.Factory.FromAsync method.

For this example I am going to call the following  Web service  to get the weather information for given Zip code.

image

when adding this above Web Service Reference we need to check  Generate asynchronous Operations. so that VS.NET will generate Async method calls. 

image

First Create Instance of the web service Proxy. and Create the Task with Begin and End methods which you are going to invoke on Web Service.  Basically this web service takes input as Zip code and returns as 1 week Weather forecast info  .

image

 

Here is the weather result for the Zipcode =75023

image

suppose Web service response is null then I can canceling the task .  here is the result for unknown zip code.

image

Here I am scheduling a continuation task once we get the response from Web Service. I feel this way of calling Web Service is more convenient than an IAsyncResult.

Nandri(Thanks)

SreenivasaRagavan.

Parallel Programming in .NET 4.0 Cancelling Tasks PART-III.

In this Blog post we are going to see how we can cancel the Task which is already running. Here is the steps we need to perform to cancelling the running Task.

1) First  create the   image .

2) Get the CancellationToken from CancellationTokenSource  Token Property.

3) Pass the CancellationToken  Token when we creating the Task or Task<T>.

image

Now to cancel the running Task simply call the  Cancel() method on image class variable instance.

For a better implementation of cancellation, the task itself can regularly poll the token by calling token.ThrowIfCancellationRequested (), so that the task will be canceled even if it has already started running by the time the token was canceled.

Here is an Action

Cancellation by Polling

image

 

Registering the Cancellation Delegate

You can register the callback method when Task Cancellation is requested. This type of Cancellation very useful in UI application .

image

Nandri(Thanks)

Sreenivasaragavan

Parallel Programming .NET Framework 4.0 PART-II

In my last Blog  post http://mstecharchitect.blogspot.com/2011/02/parallel-programming-in-net-40.html I introduced the Task Class. Now we are going to see how we can get Computed values from asynchronously executed Task using Task<T>.

Here is the  Example returning values from Task.

image

Here the above task body delegate returns a value that is exposed via the Result property on the task. When you access the Result property, you will get the result immediately if the task has already completed, or otherwise the call will block until the computation completes.

Next we are going execute two Tasks and wait for them to complete and print their Results .

image

Nandri(Thanks)

Sreenivasaragvan

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.

Sunday, February 13, 2011

Oracle Released ODAC [Oracle Data Access Components]

I think personally this is great news for me.   Now we use use Oracle DB to created LINQ and EF  Entity's.   here is the beta version of ODAC you can download and test it.

http://www.oracle.com/technetwork/topics/dotnet/downloads/oracleefbeta-302521.html

   

image

Nandri(Thanks)

Sreenivasaragavan

Saturday, February 12, 2011

IE 9 Release Candidate RC- Really Cool

 

Download the Internet Explorer 9 Release Candidate to see what’s new

http://msdn.microsoft.com/en-us/ie/default.aspx?WT.mc_id=MSCOM_HP_US_F_113LSUS004275

Internet Explorer 9 RC Now Available
Download the Internet Explorer 9 Release Candidate to see what’s new

image

image

Nandri(Thanks)

SreenivasaRagavan

Thursday, February 10, 2011

Custom Configuration Section in .NET Apps

In this Blog post I am going to write how to define Custom Configuration section in .NET Apps either App.Config or Web.config  and how to use it our programs

Here are the Steps we need to perform

1)  First Create the class which is derived from ConfigurationSection this class resides inside System.Configuration Namespace.

2) Next we need Define Our custom configuration section in our App.config or Web.Config file.  for example here is my custom configuration looks like .

image

3) Next we need to create two more classes which Reads our configuration Key and Key collection

    Here Key are Name and Value

image

image

 

Next we need to Read Key collection so here is how the class for that

image

Here we are creating Indexer to store key collection as object.

 

 

Here is how we use it our program

image

 

image

 

Nandri(thanks)

SreenivasaRagavan