: Part 1 : Working With Jquery Validation Plugin

This jQuery plugin makes clientside form validation simple, effective and easy. It makes a good choice for  scratch application as well as when you’re trying to integrate something into an existing application with lots of existing markup. Jquery validation comes with pre-defined set of validation at the same time developer can easily extend or introduces new validations.

For the latest stable release of jquery visit : Jquery CDN

Getting Started 

Step 1  : Add reference of jquery and jquery validation plugin.To get latest uri of validation plugin visit : JSCDN. For the demo i am refereing following uri



Initializing Jquery Validation 

Validator 

The validate method returns a Validator object that has a few public methods that you can use to trigger validation programmatically.

Writing Basic form Validation

i have created following examples, to demonstrate jquery validation 

Field Required

posted under , | 0 Comments

Task Parallel Libraray vs Threading

1. Create a Console Application in VS2010 name TaskParallelLibraray 2. Include Following Name Spaces in Program.CS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Diagnostics;
using System.Collections;
using System.Threading.Tasks;

3 Write Below code inside Class Program in Program.CS
static void Main(string[] args)
   {
      try
       {
          // CREATE A TREE WITH ~1023 NODES
          Tree tree = Tree.CreateSomeTree(10, 1);

          // START THE STOP WATCH
          Stopwatch sw = Stopwatch.StartNew();
                
          //WALK THE TREE
          WalkTree(tree);

          // GET THE TIME ELAPSED
           Console.WriteLine("Time Elapsed = " + sw.ElapsedMilliseconds.ToString());
                
          // WAIT TO SEE RESULTS
          Console.ReadLine();
          }
          catch (Exception ex)
          {
                Console.WriteLine(ex.Message);
                Console.Read();
          }
       }

        // WALK THE TREE USING RECURSION
        static void WalkTree(Tree tree)
        {
            //RETURN WHEN THERE ARE NO MORE CHILDRENS
            if (tree == null) return;

            #region USING TRADITIONAL SEQUENTIAL APPROACH

            WalkTree(tree.Left);
            WalkTree(tree.Right);

            #endregion

            #region USING THREADING

            // ************ PROCESS EVERY NODE USING THREADING
            // THIS MAY GIVE FOLLOWING EXCEPTION
            // An unhandled exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll
            // BECAUSE WHENEVER NEW THREAD CREATED IT REQUIRE TO STORE PREVIOS THREAD STATE WHICH IS MORE MEMORY CONSUMING IN THIS EXAMPLE

            //Thread left = new Thread(() => WalkTree(tree.Left));
            //left.Start();
            //Thread right = new Thread(() => WalkTree(tree.Right));
            //right.Start();

            //// WAIT/JOIN ON BOTH OF THEM TO COMPLETE
            //left.Join();
            //right.Join();

            //************ Process every node using thread - End

            #endregion

            #region USING TASKS PARALLEL LIBRARY THAT IS USING TASK

            //Task left = new Task(() => WalkTree(tree.Left));
            //left.Start();
            //Task right = new Task(() => WalkTree(tree.Right));
            //right.Start();
            //left.Wait();
            //right.Wait();

            #endregion

            ProcessItem(tree.Data);
        }

        // SPINWAIT PUTS PROCESSOR IN TIGHT LOOP, WITH LOOP COUNT SPECIFIED IN ITERATION  PARAMETER
        private static int ProcessItem(int p)
        {
            // THIS IS WHERE COMPUTE/BUSINESS LOGIC GOES
            Thread.SpinWait(4000000); // CONTRAST WITH THREAD.SLEEP
            return p; // not used
        }


4. Add Class name Tree.cs and paste following code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TaskParallelLibraray
{
    public class Tree
    {
        public Tree Left = null;
        public Tree Right = null;

        public int Data = 0;

        // Tree of depth 3 and start of 1
        // each node will have children left and right
        // value will increase based on depth
        //       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;
        }
    }
}
5. Run this program in a machine having dual core or core to duo processor and c the out put Almost all our servers are having multicore processor :D so performance will be great on servers rather than out Desktops Reference :MSDN

posted under , , | 0 Comments
Older Posts

We have seen by

    Followers

    Translate


Recent Comments