Tuesday, February 28, 2012

Write less do more, Juice UI for Asp.Net WebForms

At MVP Summit that was held today, Scott Hunter commented about an open source project “Juice UI”, it is more or less like the ajax control toolkit for asp.net except that Juice UI is a collection of Jquery components, that is targeted for Webforms developers. To use it you need to install Juice UI Nuget Package to your project, right click on project reference and click Manage Nuget Packages and search for Juice UI.

Official Website: http://juiceui.com
Controls List at: http://juiceui.com/controls

When the installation completes you will get some new scripts files in your script folder.

Also in web.config you will get something like this…

Now on the aspx page add a script manager, a textbox and then a juice ui autocomplete.

Here I have defined the Minimum length of autocomplete to 3 and source to some random data
Note: targetcontrolid must match the id of the textbox.

Now the autocomplete is ready for action..

Sunday, February 26, 2012

TPL or Task Parallel Library (Parallel.Invoke)

TPL or Task Parallel Library:

It is a set of public types and APIs, which are under the namespaces of the .Net 4 Framework


In short the purpose of the TPL is to make developers more productive by simplifying the process of adding parallelism and concurrency to applications. 


The TPL scales the degree of concurrency dynamically to most efficiently use all the processors that are available. The TPL handles the partitioning of the work, the scheduling of threads on the ThreadPool, cancellation support, state management, and other low-level details. 
It can maximize the performance of your code while focusing on the work that your program is designed to accomplish. 


Not all code is suitable to work in parallel; for example if i have a loop that iterates few times or it performs a small amount of work, the overhead would be visible in the performance of the application, causing it to work slower as compared running the code in serial.  
It adds complexity to the program. 
Based on my experience the threadpool culture may not match the culture of applications that were upgraded from previous version of .net framework.

To use TPL in our code first we will add both namespaces: 

using System.Threading;
using System.Threading.Tasks;

First let's look at Parallel.Invoke method

                () =>                   
                () =>
                () =>
catch (AggregateException e)
            string AggregateError = e.InnerException.ToString();

Now, what happens here is that SomeMethod A, B and C will run concurrently, if you look in the catch exception I used AggregateException, in TPL you will probably use it more often. Basically it is used to consolidate multiple failures into a single, throwable exception object.