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.

Friday, January 20, 2012

ASP.NET MVC2: Basics part 9 with Scott Hanselman

ASP.NET MVC2: Basics part 8 with Scott Hanselman

ASP.NET MVC2: Basics part 7 with Scott Hanselman

ASP.NET MVC2: Basics part 6 with Scott Hanselman

ASP.NET MVC2: Basics part 5 with Scott Hanselman

ASP.NET MVC2: Basics part 4 with Scott Hanselman

ASP.NET MVC2: Basics part 3 with Scott Hanselman

ASP.NET MVC2: Basics part 2 with Scott Hanselman

ASP.NET MVC2: Basics part 1 with Scott Hanselman

Asynchronous Controller on MVC

The AsyncController class enables you to write asynchronous action methods. Asynchronous action methods can be used for long-running, non-CPU bound requests. This avoids blocking the Web server from performing work while the request is being processed. On MVC, web services must use AsyncController class for long-running calls.

Change the Controller to AsyncController so that it inherits base class of AsyncController.

In the Model folder create a class

Back to the controller add IndexAsync Action, using TPL

And finally return data with the view