Welcome to MSDN Blogs Sign in | Join | Help

Wriju's BLOG

.NET and everything
Patterns for Parallel Programming

WOW!!! When I first saw it.

 

Patterns for Parallel Programming: Understanding and Applying Parallel Patterns with the .NET Framework 4

 

http://www.microsoft.com/downloads/details.aspx?FamilyID=86b3d32b-ad26-4bb8-a3ae-c1637026c3ee&displaylang=en

 

You must must read it!!!

 

Namoskar!!!

 

VB.NET 10 : Optional Nullable Parameter

If you want to assign Nothing to the optional parameter in VB.NET 10, it is just like to obvious now,

Sub Main()

    'Passing value for the optional parament _age

    MyFunc("Wriju", "wriju@contoso.com", 30)

 

    'No value is supplied for the optional parament _age

    MyFunc("Writam", "writam@contoso.com")

End Sub

 

 

Sub MyFunc(ByVal _name As String,

           ByVal _email As String,

           Optional ByVal _age As Integer? = Nothing)

 

    Console.WriteLine("Name={0}, Email={1}, Age={2}",

                      _name, _email, _age.ToString())

End Sub

 

Namoskar!!!

VB.NET 10 : Multiline Lambdas

With implicit line continuation VB.NET 10 now allows you to write the multiline Lambdas. That means like your normal Functions you can write functions under Lambdas.

So now you may write like,

Dim arrInt As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

 

Dim myFinc = Array.FindAll(arrInt, Function(n)

                                       If n Mod 2 = 0 Then

                                           Console.WriteLine("{0} is Even", n)

                                       Else

                                           Console.WriteLine("{0} is not Even", n)

                                       End If

                                   End Function)

 

Namoskar!!!

Parallel Computing: PLINQ

Visual Studio 2010 has new API for LINQ (Language Integrated Query). This helps us to implement the power of Parallel Computing in declarative manner.

LINQ without Parallel Extension

It will take 3 sec for 28 thousand elements.

static void Main(string[] args)

{

    Stopwatch sw = Stopwatch.StartNew();

   

    DoIt();

 

    Console.WriteLine("Elapsed = " + sw.ElapsedMilliseconds.ToString());

    Console.ReadLine();

}

 

private static void DoIt()

{

    IEnumerable<int> arrInt = Enumerable.Range(1, 4000000);

    var q =

        from n in arrInt

        where IsPrime(n)

        select n.ToString();

 

    List<string> list = q.ToList();

 

    Console.WriteLine("Elements : " + list.Count.ToString());

}

 

private static bool IsPrime(int p)

{

    //Find the prime number

    int upperBound = (int)Math.Sqrt(p);

    for (int i = 2; i < upperBound; i++)

    {

        if (p % i == 0) return false;

    }

    return true;

}

 

LINQ with Parallel Extension

With a very simple change in query this will take around 1.5 sec for the same number of elements.

var q =

    from n in arrInt.AsParallel()

    where IsPrime(n)

    select n.ToString();

 

Greenroom

What’s the magic? When we use .AsParallel() it does cast the list of integers into ParallelEnumerable class and calls a different Where method which implements the new “Task” API.

With Lambda expression this would look more clear.

Before

var q = arrant

    .Where(n => IsPrime(n))

    .Select(n => n.ToString());

 

Class: Enumerable

 

Method:     

        public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate);

 

After (while using AsParallel())

Code:

var q = arrInt.AsParallel()

    .Where(n => IsPrime(n))

    .Select(n => n.ToString());

 

Class : ParallelEnumerable

 

Method :

        public static ParallelQuery<TSource> Where<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate);

 

The above time will vary based on CPU power and availability.

Namoskar!!!

Parallel Computing: The new “Task” API

Visual Studio 2010 has new API called “Task”. This helps us to create small pieces of work and execute in distributed manner under multi core machine. Unlike thread it has flexibility to adopt the lower number of CPU without changing code. With improved CLR thread pool local processes are not confined in local thread pool rather it can leverage the available ppol in the memory. The below I am going to show how traditional Thread and Task works.

Background

We have utility function which helps us to iterate through a in memory tree.

class Tree

{

    public Tree Left = null;

    public Tree Right = null;

 

    public int Data = 0;

 

    //       1 

    //   2       2

    // 3   3   3   3

    //4 4 4 4 4 4 4 4

 

    internal static Tree CreateSomeTree(int depth, int start)

    {

        Tree root = new Tree();

        root.Data = start;

 

        if (depth > 0)

        {

            root.Left = CreateSomeTree(depth - 1, start + 1);

            root.Right = CreateSomeTree(depth - 1, start + 1);

        }

 

        return root;

    }

}

 

Normal Approach

In 2 CPU machine it takes around 29 sec.

static void Main(string[] args)

{

    Tree tr = Tree.CreateSomeTree(9, 1); //Will create 1023 nodes

    Stopwatch sw = Stopwatch.StartNew();

 

    WalkTree(tr);

  

    Console.WriteLine("Elapsed = " + sw.ElapsedMilliseconds.ToString());

    Console.ReadLine();

}

 

static void WalkTree(Tree tr)

{

    if (tr == null) return;

 

    WalkTree(tr.Left);

    WalkTree(tr.Right);

   

    ProcessItem(tr.Data);

}

       

static int ProcessItem(int treeData)

{

    //Just for Demo purposes

    Thread.SpinWait(4000000);

 

    return treeData;

}

 

Thread Approach

Now if we try to implement Thread in Walk tree it would take around 15 sec.

static void WalkTree(Tree tr)

{

    if (tr == null) return;

 

    Thread left = new Thread(() => WalkTree(tr.Left));

    left.Start();

 

    Thread right = new Thread(() => WalkTree(tr.Right));

    right.Start();

 

    left.Join();

    right.Join();

 

    ProcessItem(tr.Data);

}

 

Task Approach

The same code using Task API would again take nothing more than 9 sec.

static void WalkTree(Tree tr)

{

    if (tr == null) return;

 

    Task left = new Task(() => WalkTree(tr.Left));

    left.Start();

 

    Task right = new Task(() => WalkTree(tr.Right));

    right.Start();

 

    left.Wait();

    right.Wait();

 

    ProcessItem(tr.Data);

}

 

The above time will vary based on CPU power and availability.

Namoskar!!!

Seven Things to Know about Windows 7

image

1) Simple to Use. The Snap feature arranges windows side-by-side by dragging programs. You can then pin your favorite programs to the Windows Taskbar. Finding often-used programs and files is easier with Windows 7. The streamlined user interface includes a cleaner desktop and task bar. Using the Jump Lists feature, you can place the cursor over graphic thumbnails to see a preview of recently viewed files.

2) Faster. PCs start up and shut down faster by reducing background services. PCs also sleep and resume more quickly. 64-bit editions of Windows 7 take full advantage of the increased RAM and multi-tasking capabilities of 64-bit PCs.

3) More Reliable. Windows Vista applications or devices should run on Windows 7, and Windows Vista systems will run Windows 7 faster. Battery life also improves with trigger-start services.

4) Better Compatibility. Windows 7 will considerably reduce compatibility issues seen in previous operating system releases. Built with compatibility issues in mind and through the great work of the Compatibility Assistance Support Team (CAST), existing applications will run on Windows 7.

5) Easy Web Browsing. Keep track of important information without constantly returning to websites with the Web Slides feature. Bundled with Internet Explorer 8, Web search results will now include pictures and previews allowing for quicker page loads, the ability to view two pages side-by-side if desired, and better security to protect against cyberspace attacks.

6) More Secure. User Account Controls alert you if an unknown program tries to run on your PC and, unlike Vista, most protection - which includes Windows Defender's anti-spyware software and Windows Firewall - takes place unobtrusively in the background. On a related note, Windows 7’s new backup program makes it easier and more intuitive for users to back up individual files and folders.

7) The Hub of your Digital Life. Sharing data across all of your PCs and mobile devices will be a lot easier with faster and more reliable synchronization. Also, Windows 7 provides a smooth integration with Windows Live services. For personal, at-home use, the HomeGroup feature is easy to use and takes just found steps to set up a wireless home network.

Namoskar!!!

Visual Studio 2010 Beta 2

I have installed the Beta 2 of Visual Studio 2010. I love its splash screen

image

Go get it and enjoy!!!

Find more information at http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx

MSDN Subscribers: Download the Beta

The Visual Studio 2010 and .NET Framework Beta 2 is available to MSDN subscribers on Monday, October 19th, with general availability on October 21st.

How to Download and Install the Beta

Are you excited to try Beta 2, but not excited about reading the installation documentation? This video will show you how to download and install Beta 2 of Visual Studio 2010, Team Foundation Server and .NET Framework 4. Start your downloads!

Featured Overviews and Walkthroughs

Check out this diverse collection of walkthroughs for Beta 2. They provide step-by-step instructions for common scenarios and are a good place to start learning about Visual Studio 2010 and .NET Framework 4.

Namoskar!!!

VB.NET 10 : Array Literals

VB.NET has another exiting feature which helps us to declare and initialize an array without explicitly specifying the type and dimension. This infers at compile time. Good for Lazy developer like me J

Dim arrInt = {1, 2, 3, 4, 5, 6, 7} 'becomes Integer()

 

Dim arrDouble = {1, 2, 3, 4, 5, 6, 7.9} 'becomes Double()

 

Dim arrString = {1, 2, 3, 4, 5, "Six"} 'becomes String()

 

Dim arrString2 = {"One", "Two", "Three"} 'becomes String()

 

Dim arr2D = {{1, 2, 3}, {4, 5, 6}} 'becomes Integer(,)

Namoskar!!!

VB.NET 10 : Nullable Optional Parameter

You can create method with optional parameter and also make them Nullable.

Optional with default value

Sub Test(ByVal _name As String, ByVal _email As String, Optional ByVal _age As Integer = 30)

 

Optional and Nullable

Sub Test(ByVal _name As String, ByVal _email As String, Optional ByVal _age As Integer? = Nothing)

Similarly you also may initialize the collection like Dictionary.

Namoskar!!!

VB.NET 10 : Collection Initializer

Another useful feature which was missing in VB.Net 9 is available in Visual Studio 2010. This provides option to declare and initialize with series of values with the keyword Form.

Dim myList As New List(Of Integer) From {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

 

For Each i In myList

    Console.WriteLine(i)

Next

Similarly you also may initialize the collection like Dictionary.

Dim myDic As New Dictionary(Of Integer, String) From {{1, "One"}, {2, "Two"}}

Namoskar!!!

Podcast : Parallel Computing in Visual Studio 2010 – “Task” API

 

Download Link from here

http://silverlight.services.live.com/93612/Parallel%20Computing%20in%20Visual%20Studio%202010%20Beta%201%20-%20Task%20API/video.wmv

 

Namoskar!!!

Web Application Toolkits to the Web Announcement

 

image Today with the announcement of Microsoft WebsiteSpark, we are launching a number of Web Application Toolkits to the Web. Web Application Toolkits are designed to enable Web Developers to simply extend their web application capabilities by providing them with a packaged set of running samples, templates and documentation.

 

 

The goal for the Web Application Toolkits is to provide Web Developers with resources such as project templates, controls, and code samples along with simplified documentation all in a consistent packaged format that is easy to download and run in a very short period of time. One of the key criteria around the Web Application Toolkits is to enable Web Developers to get to an F5 (Run) experience very quickly to ensure that this is the right solution for their problem; How many times have you heard developers trying for hours to get a sample to work only to find it does not do what they expected. The expectation is that with the correct prerequisites installed using the Web Platform Installer, a Web Developer can have a Web Application Toolkit sample application installed and running in 5mins.

 

For the Microsoft WebsiteSpark launch, we have released 7 Web Application Toolkits, together with an introduction to the Web Application Toolkits on Channel9 by James Senior and Jonathan Carter. The scenarios were selected based on feedback from community developers with the first 7 being detailed below.  

 

image

Web Application Toolkit for Internet Explorer 8 Extensibility

 

Today users can access rich information and services while they are browsing a site; it's not a trivial task to expose this content to the same users when they are not on that site. The goal of this Web Application Toolkit is to leverage the new features in Internet Explorer 8 (Web Slices, Accelerators and Visual Search Providers) to extend the reach of your web site and services also to those users that are not on your site. The Web Application Toolkit includes a set of ASP.NET Web Controls that you can use to take advantage of these IE new features in your own Web application.

Check out the accompanying screencast.

image

Web Application Toolkit for Bing Search

 

Bing is a powerful new Decision Engine designed to help consumers accomplish tasks and make faster, more informed decisions. The Bing Application Programming Interface (API) provides developers programmatic access to Bing, offering flexible options for building or enhancing your site or applications. This Web Application Toolkit shows how to take advantage of the Bing API to add search capabilities to your Web site by leveraging the various search results that the Bing API provides, including Web content, images, news and videos, among others. Through this Web Application Toolkit you will also discover how to use ASP.NET AJAX and jQuery to provide an enhanced and more interactive end user experience when using the Bing API.

 

 

image

Web Application Toolkit for REST Services

 

Many Web applications today are starting to expose data as REST service interfaces, so it can be accessed through APIs by other tiers of the application or even by other applications. A RESTful web service is a simple Web service implemented using HTTP and the principles of REST. REST Services focus on resources; each one is represented by a unique URI, and users interact with them via their URI using the HTTP uniform interface. This Web Application Toolkit shows how to easily add REST service interfaces for an existing Web application. The Web Application Toolkit includes a sample REST service, two sample client applications that access the REST services, one using simple ASP.NET Web Forms and a second Web application using AJAX to asynchronously invoke the REST service and finally a custom project template for Visual Studio to make it very easy to build new REST Services.

Check out the accompanying screencast.

 

image

Web Application Toolkit for Mobile Web Applications

 

This Web Application Toolkit is designed to demonstrate how to extend an existing ASP.NET MVC Web application to provide access from mobile devices. To enable mobile access, the Web application should have views targeting each of the mobile devices to be supported. The MVC pattern helps you create applications that separate the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements.  This Web Application Toolkit provides a component called MobileCapableViewEngine that enables the Web application to show the appropriate view depending on the device's browser that is performing the request.   It also includes a sample site that provides different views for Windows Mobile, IPhone, and Blackberry devices.  

Check out the accompanying screencast.

 

image

Web Application Toolkit for Template-Driven Email

 

This Web Application Toolkit is designed to demonstrate how to generate and send dynamic, template-based emails from a web application. There are many common scenarios where notification emails need to be sent to end users. Examples of these common scenarios may involve notifying a user of their newly created account, sending a new password in respond to a forgotten password request, or emailing an alert under specific business circumstances, such as the creation of a order. Typically the E-mails sent from a Web application scenario are formatted as HTML, include CSS stylesheets, and images and need to be generated dynamically with custom or user-specific data.  This Web Application Toolkit includes samples that show how to use templates to generate these dynamic email bodies. 

Check out the accompanying screencast.

 

image

Web Application Toolkit for making Your Web Site Social

Adding social capabilities to your Web site allows you to attract new users, keep them on your Web site for longer and get them to come back more often. This Web Application Toolkit shows how, using a few lines of code with the Windows Live Messenger Web Toolkit, it is possible to add social capabilities to a Web site with instant messaging from a website to various client endpoints like Windows, Windows Mobile, Xbox 360 and Mac.  Behind the scenes is a powerful set of UI Controls and a JavaScript library that connect your website to the Messenger Service which is used by 330 million users around the world. 

Check out the accompanying screencast.

image

Web Application Toolkit for FAQs

 

The majority of web sites have the need to display a list of frequently asked questions to their users. Although it's not difficult to create a simple set of FAQ pages, creating a great user experience that supports searching for FAQs, filtering, and paging, can become more difficult. Furthermore, this is often common functionality that has to be implemented repeatedly in multiple Web sites. This Web Application Toolkit is designed to provide a starting set of code including ASP.NET pages, data access logic, and database schemas, for integrating Frequently Asked Questions into your own ASP.NET MVC Web application.

Check out the accompanying screencast.

 

 

 

You can find the complete list of Web Application Toolkits here.   With this initial release of 7 Web Application Toolkits, we are just getting started.  We have plans for several more and we are exploring additional ways to make it easier for Web Developers to find and reuse this content. 

Scott Hanselman's 2009 Ultimate Developer and Power Users Tool List for Windows

Another super compilation http://www.hanselman.com/blog/ScottHanselmans2009UltimateDeveloperAndPowerUsersToolListForWindows.aspx

Namoskar!!!

What’s new in ASP.NET 4.0 and Visual Studio Beta 2?

List is quite big!!!

 

Core Services

   Web.config File Minification

   Extensible Output Caching

   Auto-Start Web Applications

   Permanently Redirecting a Page

   The Incredible Shrinking Session State

   Expanding the Range of Allowable URLs

   Extensible Request Validation

   Object Caching and Object Caching Extensibility

   Extensible HTML, URL, and HTTP Header Encoding

   Performance Monitoring for Individual Applications in a Single Worker Process

   Multi-Targeting

New Features in ASP.NET AJAX 4

   Client Template Rendering

   Instantiating Behaviors and Controls Declaratively

   Live Data Binding

   Using the Observer Pattern with JavaScript Objects and Arrays

   The DataView Control

   The AdoNetServiceProxy Class

   The DataContext and AdoNetDataContext Classes

   Refactoring the Microsoft AJAX Framework Libraries

   The DOM Ready Event

   Using JSONP to Retrieve Cross-Domain Data.

Web Forms

   Setting Meta Tags with the Page.MetaKeywords and Page.MetaDescription Properties

   Enabling View State for Individual Controls

   Changes to Browser Capabilities

   Routing in ASP.NET 4

   Setting Client IDs

   Persisting Row Selection in Data Controls

   ASP.NET Chart Control

   Filtering Data with the QueryExtender Control

   Html Encoded Code Expressions

   Project Template Changes

   CSS Improvements

   Hiding div Elements Around Hidden Fields.

   Rendering an Outer Table for Templated Controls

   ListView Control Enhancements

   CheckBoxList and RadioButtonList Control Enhancements

   Menu Control Improvements

   Wizard and CreateUserWizard Controls

ASP.NET MVC

Dynamic Data

   Enabling Dynamic Data for Existing Projects

   Declarative DynamicDataManager Control Syntax

   Entity Templates

   New Field Templates for URLs and E-mail Addresses

   Creating Links with the DynamicHyperLink Control

   Support for Inheritance in the Data Model

   Support for Many-to-Many Relationships (Entity Framework Only)

   New Attributes to Control Display and Support Enumerations

   Enhanced Support for Filters

Visual Studio 2010 Web Designer Improvements

   Improved CSS Compatibility

   HTML and JScript Snippets

   JScript IntelliSense Enhancements.

Web Application Deployment with Visual Studio 2010

   Web Packaging

   Web.config Transformation

   Database Deployment

   One-Click Publish for Web Applications

   Resources

 

Find at http://www.asp.net/learn/whitepapers/aspnet40/, more whitepapers on ASP.Net can be found at http://www.asp.net/learn/whitepapers/

 

Namoskar!!!

Podcast : C# 4.0 - Dynamic Object

I thought I will start the series of podcasting. This one is on Dynamic Object of C# 4.0

 

Namoskar!!!

More Posts Next page »
Page view tracker