<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Tanzim Saqib on .NET discovery &#187; JavaScript</title>
	<atom:link href="http://tanzimsaqib.wordpress.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://tanzimsaqib.wordpress.com</link>
	<description>Innovate. Create. Share.</description>
	<lastBuildDate>Wed, 19 Nov 2008 10:04:28 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='tanzimsaqib.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/756ba5f132c23525771f86885e65d27c?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Tanzim Saqib on .NET discovery &#187; JavaScript</title>
		<link>http://tanzimsaqib.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://tanzimsaqib.wordpress.com/osd.xml" title="Tanzim Saqib on .NET discovery" />
		<item>
		<title>CallQueue: Implementing a Sequential Web Service Call Queue for AJAX application</title>
		<link>http://tanzimsaqib.wordpress.com/2008/11/19/callqueue-implementing-a-sequential-web-service-call-queue-for-ajax-application/</link>
		<comments>http://tanzimsaqib.wordpress.com/2008/11/19/callqueue-implementing-a-sequential-web-service-call-queue-for-ajax-application/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 10:04:28 +0000</pubDate>
		<dc:creator>tanzimsaqib</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://tanzimsaqib.wordpress.com/2008/11/19/callqueue-implementing-a-sequential-web-service-call-queue-for-ajax-application/</guid>
		<description><![CDATA[In AJAX based applications its common that user might end up breaking your AJAX calls by clicking on numerous places in very short interval of time. Let us assume there is a page where there are several of hyperlinks which make WebService calls and do some stuffs on callback. If user clicks on five hyperlinks [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=101&subd=tanzimsaqib&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In AJAX based applications its common that user might end up breaking your AJAX calls by clicking on numerous places in very short interval of time. Let us assume there is a page where there are several of hyperlinks which make WebService calls and do some stuffs on callback. If user clicks on five hyperlinks being impatient or may be just for fun, there will be five different WebService calls made. All of those calls had the same parameters or UI state while they were invoked. But on completion of one or more WebService calls it may happen that the UI state or data passed to the rest of the WebServices calls no longer exist or expired, thus will be result in inconsistent UI behaviour and/or invalid data. This is one of the important scenarios an AJAX developer should consider when he designs an application. </p>
<p><strong>The Specification<br /></strong>To address the scenario, I would prefer implementing a Sequential WebService Calls Queue which will be able to schedule the tasks/WebService calls and help keeping UI and data consistent over the AJAX calls. We should achieve the following features from this queue:</p>
<ul>
<li>Enqueue any WebService call anytime in the application.
<li>Dequeue any previously queued call regardless of currently executing call and location in the application.
<li>Each WebService call should have an identifier so that we can track the call and dequeue anytime later by SSQ.dq(call_id).
<li>Each call should have a timeout value which will determine the maximum amount of time we will consider for that particular call before we invoke the next call, after that we will remove from the queue.
<li>A timer will act as scheduler but will not run forever. It should run only when necessary.
<li>Each call should be able to declare its completion at any time by notifyCompleted, so that the scheduler timer will not wait for the prior task and should dequeue the next call.
<li>notifyCompleted should also be optional. The currently running call should automatically be dequeued from the scheduler queue after the timeout of its own.
<li>Each call should be able to mark as replaceIfExists so that if user`s any activity already enqueued this call, should be replaced by the current one.
<li>The queue instance should be exclusively available to the user and all over the page, meaning that the same queue class will be used to serve the functionality in one page per user basis.</li>
</ul>
<p><strong>The Usage<br /></strong>You should be able to use this library as follows:</p>
<ol>
<li>Include GenericQueue.js and SequentialServiceQueue.js to your project
<li>Add the reference in the pages that you want them to be used</li>
</ol>
<p>We will be naming the class as SequentialServiceQueue and in short SSQ. Let us have a look at the WebService calls in Service Queue fashion:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:fc2046a6-27d0-4752-a768-75c189e3c3e0" class="wlWriterSmartContent">
<pre style="background-color:White;overflow:auto;">
<div><span style="color:#0000FF;">var</span><span style="color:#000000;"> id1 </span><span style="color:#000000;">=</span><span style="color:#000000;"> SSQ.nq(</span><span style="color:#000000;">'</span><span style="color:#000000;">SomeMethod1</span><span style="color:#000000;">'</span><span style="color:#000000;">, </span><span style="color:#0000FF;">false</span><span style="color:#000000;">, </span><span style="color:#000000;">1000</span><span style="color:#000000;">,
    </span><span style="color:#0000FF;">function</span><span style="color:#000000;">()
    {
        </span><span style="color:#008000;">//</span><span style="color:#008000;"> Do some stuffs</span><span style="color:#008000;">
</span><span style="color:#000000;">        SomeWebService1.SomeMethod1(SomeParameters, onSomeMethodCallCompleted);
    });

</span><span style="color:#0000FF;">function</span><span style="color:#000000;"> onSomeMethodCallCompleted(result)
{
    </span><span style="color:#008000;">//</span><span style="color:#008000;"> Do stuffs</span><span style="color:#008000;">
</span><span style="color:#000000;">    SSQ.notifyCompleted(id1);
}

</span><span style="color:#0000FF;">var</span><span style="color:#000000;"> id2 </span><span style="color:#000000;">=</span><span style="color:#000000;"> SSQ.nq(</span><span style="color:#000000;">'</span><span style="color:#000000;">SomeMethod2</span><span style="color:#000000;">'</span><span style="color:#000000;">, </span><span style="color:#0000FF;">false</span><span style="color:#000000;">, </span><span style="color:#000000;">1000</span><span style="color:#000000;">,
    </span><span style="color:#0000FF;">function</span><span style="color:#000000;">()
    {
        </span><span style="color:#008000;">//</span><span style="color:#008000;"> Do some stuffs</span><span style="color:#008000;">
</span><span style="color:#000000;">        SomeWebService2.SomeMethod2(SomeParameters,
            </span><span style="color:#0000FF;">function</span><span style="color:#000000;">(result)
            {
                </span><span style="color:#008000;">//</span><span style="color:#008000;"> Do stuffs</span><span style="color:#008000;">
</span><span style="color:#000000;">                SSQ.notifyCompleted(id2);
            });
    });</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>You can not only queue WebService calls, but also regular JavaScript codeblock:</p>
<div style="width:619px;display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:27c0c167-37c3-4e49-a541-ba0fa9b18eb8" class="wlWriterSmartContent">
<pre style="background-color:White;overflow:auto;">
<div><span style="color:#0000FF;">var</span><span style="color:#000000;"> service_id1 </span><span style="color:#000000;">=</span><span style="color:#000000;"> SSQ.nq(</span><span style="color:#000000;">'</span><span style="color:#000000;">Service1</span><span style="color:#000000;">'</span><span style="color:#000000;">, </span><span style="color:#0000FF;">false</span><span style="color:#000000;">, </span><span style="color:#000000;">1000</span><span style="color:#000000;">,
    </span><span style="color:#0000FF;">function</span><span style="color:#000000;">()
    {
        </span><span style="color:#008000;">//</span><span style="color:#008000;"> Do some stuffs</span><span style="color:#008000;">
</span><span style="color:#000000;">        SSQ.notifyCompleted(service_id1);
    });</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p><strong>The GenericQueue<br /></strong>To accomplish the SequentialServiceQueue, first of all we should define an all purpose GenericQueue class which will able to handle any queue requirement out of the box. The queue is fairly simple, just like old Computer Science data structure class. Here are few of the functions from the class:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:3376f21b-d36c-474a-9973-b2befdf1374e" class="wlWriterSmartContent">
<pre style="background-color:White;overflow:auto;">
<div><span style="color:#0000FF;">this</span><span style="color:#000000;">.nq </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">function</span><span style="color:#000000;">(element)
{
    array.push(element);
    </span><span style="color:#000000;">++</span><span style="color:#000000;">rear;
}

</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.dq </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">function</span><span style="color:#000000;">()
{
    </span><span style="color:#0000FF;">var</span><span style="color:#000000;"> element </span><span style="color:#000000;">=</span><span style="color:#000000;"> undefined;

    </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (</span><span style="color:#000000;">!</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.is_empty())
    {
        element </span><span style="color:#000000;">=</span><span style="color:#000000;"> array.shift();
        </span><span style="color:#000000;">--</span><span style="color:#000000;">rear;
    }

    </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> element;
}

</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.for_each </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">function</span><span style="color:#000000;">(func)
{
    </span><span style="color:#0000FF;">for</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">var</span><span style="color:#000000;"> i </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">0</span><span style="color:#000000;">; i </span><span style="color:#000000;">&lt;</span><span style="color:#000000;"> rear; </span><span style="color:#000000;">++</span><span style="color:#000000;">i)
        func(i, array[i]);
}

</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.delete_at </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">function</span><span style="color:#000000;">(index)
{
    </span><span style="color:#0000FF;">delete</span><span style="color:#000000;"> array[index];

    </span><span style="color:#0000FF;">var</span><span style="color:#000000;"> i </span><span style="color:#000000;">=</span><span style="color:#000000;"> index;
    </span><span style="color:#0000FF;">while</span><span style="color:#000000;"> (i </span><span style="color:#000000;">&lt;</span><span style="color:#000000;"> array.length)
        array[i] </span><span style="color:#000000;">=</span><span style="color:#000000;"> array[</span><span style="color:#000000;">++</span><span style="color:#000000;">i];

    array </span><span style="color:#000000;">=</span><span style="color:#000000;"> array.slice(</span><span style="color:#000000;">0</span><span style="color:#000000;">, </span><span style="color:#000000;">--</span><span style="color:#000000;">rear);
}</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p><strong>The SequentialServiceQueue</strong><br />The following is how this class starts. You will notice here that the timer_id is for our scheduler timer, running_task indicates the currently executing call, interval is a variable for the timer_id which you can determine as your wish. interval is the knob of how fast or slow you want the scheduler to run. queue as you can understand is an GenericQueue instance we have just created above. Note that the GenericQueue is not a static class rather its a instance class unlike the SSQ. You have also noticed that the ms_when_last_call_made and ms_elapsed_since_last_call are pretty self-describing. get_random_id is reponsible for preparing new id for the newly enqueued call.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:b4286d51-b175-49f5-8944-59bed7e1fd96" class="wlWriterSmartContent">
<pre style="background-color:White;overflow:auto;">
<div><span style="color:#0000FF;">var</span><span style="color:#000000;"> SequentialServiceQueue </span><span style="color:#000000;">=</span><span style="color:#000000;">
{
    timer_id: </span><span style="color:#0000FF;">null</span><span style="color:#000000;">,
    ms_when_last_call_made: </span><span style="color:#000000;">0</span><span style="color:#000000;">,          </span><span style="color:#008000;">//</span><span style="color:#008000;"> milliseconds (readonly)</span><span style="color:#008000;">
</span><span style="color:#000000;">    ms_elapsed_since_last_call: </span><span style="color:#000000;">0</span><span style="color:#000000;">,      </span><span style="color:#008000;">//</span><span style="color:#008000;"> milliseconds (readonly)</span><span style="color:#008000;">
</span><span style="color:#000000;">    running_task: </span><span style="color:#0000FF;">null</span><span style="color:#000000;">,
    interval: </span><span style="color:#000000;">10</span><span style="color:#000000;">,                       </span><span style="color:#008000;">//</span><span style="color:#008000;"> milliseconds</span><span style="color:#008000;">
</span><span style="color:#000000;">    queue: </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> GenericQueue(),

    get_random_id: </span><span style="color:#0000FF;">function</span><span style="color:#000000;">() {
        </span><span style="color:#0000FF;">var</span><span style="color:#000000;"> min </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">1</span><span style="color:#000000;">;
        </span><span style="color:#0000FF;">var</span><span style="color:#000000;"> max </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">10</span><span style="color:#000000;">;
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> Date().getTime() </span><span style="color:#000000;">+</span><span style="color:#000000;"> (Math.round((max </span><span style="color:#000000;">-</span><span style="color:#000000;"> min) </span><span style="color:#000000;">*</span><span style="color:#000000;"> Math.random() </span><span style="color:#000000;">+</span><span style="color:#000000;"> min));
    },</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>From the code below, as soon as any new call is enqueued, we check for if it is allowed to replace if already exists in the queue with the same name. If found any, we just update that, otherwise we create a brand new task and enqueue and start our updater which is the scheduler in our case.</p>
</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:ae7c30d7-43e7-4af0-8770-8f7883c4cc68" class="wlWriterSmartContent">
<pre style="background-color:White;overflow:auto;">
<div><span style="color:#000000;">nq: </span><span style="color:#0000FF;">function</span><span style="color:#000000;">(name, replaceIfExists, timeout, code) {
    </span><span style="color:#0000FF;">var</span><span style="color:#000000;"> id </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.get_random_id();

    </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (replaceIfExists) {
        </span><span style="color:#0000FF;">var</span><span style="color:#000000;"> isFound </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">false</span><span style="color:#000000;">;
        </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.queue.for_each(
            </span><span style="color:#0000FF;">function</span><span style="color:#000000;">(index, element) {
                </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (element </span><span style="color:#000000;">!==</span><span style="color:#000000;"> undefined </span><span style="color:#000000;">&amp;&amp;</span><span style="color:#000000;"> element </span><span style="color:#000000;">!==</span><span style="color:#000000;"> </span><span style="color:#000000;">'</span><span style="color:#000000;">undefined</span><span style="color:#000000;">'</span><span style="color:#000000;"> </span><span style="color:#000000;">&amp;&amp;</span><span style="color:#000000;"> element.name </span><span style="color:#000000;">==</span><span style="color:#000000;"> name) {
                    element.id </span><span style="color:#000000;">=</span><span style="color:#000000;"> id;
                    element.replaceIfExists </span><span style="color:#000000;">=</span><span style="color:#000000;"> replaceIfExists;
                    element.timeout </span><span style="color:#000000;">=</span><span style="color:#000000;"> timeout;
                    element.code </span><span style="color:#000000;">=</span><span style="color:#000000;"> code;
                    isFound </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">true</span><span style="color:#000000;">;
                }
            });
    }

    </span><span style="color:#008000;">//</span><span style="color:#008000;"> Enqueue new task</span><span style="color:#008000;">
</span><span style="color:#000000;">    </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (</span><span style="color:#000000;">!</span><span style="color:#000000;">isFound </span><span style="color:#000000;">||</span><span style="color:#000000;"> </span><span style="color:#000000;">!</span><span style="color:#000000;">replaceIfExists) {
        </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.queue.nq(
            {
                id: id,
                name: name,
                replaceIfExists: replaceIfExists,
                timeout: timeout,
                code: code
            });
    }

    </span><span style="color:#008000;">//</span><span style="color:#008000;"> We have got new tasks, start the updater</span><span style="color:#008000;">
</span><span style="color:#000000;">    </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.startUpdater();

    </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> id;
},</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p>The following is the core part of the class which is the scheduler. Inside startUpdater, it executes the block of code in every interval we defined before. And inside the looping code, we check for if there is already any running task, if yes we check for the timeout whether it should make a good timeout or not. Otherwise we let it run as it was. However, if there is no running task at this moment, we dequeue a task and start executing the code and set a starting time for that to keep track of how long it is being running.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:1696cc4d-c248-4621-9489-a8f1c75ff909" class="wlWriterSmartContent">
<pre style="background-color:White;overflow:auto;">
<div><span style="color:#000000;">detachTask: </span><span style="color:#0000FF;">function</span><span style="color:#000000;">(id) {
    </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.dq(id);
    </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.running_task </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">;
    </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.ms_when_last_call_made </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">0</span><span style="color:#000000;">;
    </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.ms_elapsed_since_last_call </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">0</span><span style="color:#000000;">;

    </span><span style="color:#008000;">//</span><span style="color:#008000;"> See if we are done with the queued tasks</span><span style="color:#008000;">
</span><span style="color:#000000;">    </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.queue.is_empty())
        </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.stopUpdater();
},

startUpdater: </span><span style="color:#0000FF;">function</span><span style="color:#000000;">() {
    </span><span style="color:#0000FF;">var</span><span style="color:#000000;"> _self </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">;
    </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.timer_id </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) {
        </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.timer_id </span><span style="color:#000000;">=</span><span style="color:#000000;"> setInterval(
            </span><span style="color:#0000FF;">function</span><span style="color:#000000;">() {
                </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (_self.running_task </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) {
                    </span><span style="color:#008000;">//</span><span style="color:#008000;"> We dont have any running task, lets make the first one</span><span style="color:#008000;">
</span><span style="color:#000000;">                    _self.running_task </span><span style="color:#000000;">=</span><span style="color:#000000;"> _self.queue.dq();
                    </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (_self.running_task </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) {
                        _self.ms_when_last_call_made </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> Date().getTime();
                        _self.running_task.code();
                    }
                }
                </span><span style="color:#0000FF;">else</span><span style="color:#000000;"> {
                    </span><span style="color:#008000;">//</span><span style="color:#008000;"> We have a running task already</span><span style="color:#008000;">
</span><span style="color:#000000;">                    _self.ms_elapsed_since_last_call </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> Date().getTime() </span><span style="color:#000000;">-</span><span style="color:#000000;"> _self.ms_when_last_call_made;

                    </span><span style="color:#008000;">//</span><span style="color:#008000;"> Should the current task be skipped?</span><span style="color:#008000;">
</span><span style="color:#000000;">                    </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (_self.ms_elapsed_since_last_call </span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> _self.running_task.timeout)
                    </span><span style="color:#008000;">//</span><span style="color:#008000;"> Time's up. leave the task alone. Let other tasks start executing.</span><span style="color:#008000;">
</span><span style="color:#000000;">                        _self.detachTask(_self.running_task.id);
                }
            }, _self.interval);
    }
},

stopUpdater: </span><span style="color:#0000FF;">function</span><span style="color:#000000;">() {
    </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.timer_id </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) {
        clearInterval(</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.timer_id)
        </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.timer_id </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">;
    }

    </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.queue </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> GenericQueue();
},</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Keep an eye on my blog for continued development and improvements, and download CallQueue from: <a href="http://code.msdn.microsoft.com/callqueue">http://code.msdn.microsoft.com/callqueue</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tanzimsaqib.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tanzimsaqib.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tanzimsaqib.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tanzimsaqib.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tanzimsaqib.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tanzimsaqib.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tanzimsaqib.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tanzimsaqib.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tanzimsaqib.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tanzimsaqib.wordpress.com/101/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=101&subd=tanzimsaqib&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tanzimsaqib.wordpress.com/2008/11/19/callqueue-implementing-a-sequential-web-service-call-queue-for-ajax-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d65a9fc0993ccb92b3897422dbf28d84?s=96&#38;d=identicon" medium="image">
			<media:title type="html">tanzimsaqib</media:title>
		</media:content>
	</item>
		<item>
		<title>jQuery intellisense in Visual Studio</title>
		<link>http://tanzimsaqib.wordpress.com/2008/10/28/jquery-intellisense-in-visual-studio/</link>
		<comments>http://tanzimsaqib.wordpress.com/2008/10/28/jquery-intellisense-in-visual-studio/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 03:16:11 +0000</pubDate>
		<dc:creator>tanzimsaqib</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://tanzimsaqib.wordpress.com/2008/10/28/jquery-intellisense-in-visual-studio/</guid>
		<description><![CDATA[Those who are excited like me about the news of jQuery integration into Visual Studio, started adopting jQuery replacing ASP.NET AJAX Client side API. Microsoft also declared there will be a patch for Visual Studio which will support jQuery as well as intellisene for that. For the enthusiasts who just can&#8217;t for it, here is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=71&subd=tanzimsaqib&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Those who are excited like me about the news of jQuery integration into Visual Studio, started adopting jQuery replacing ASP.NET AJAX Client side API. Microsoft also declared there will be a patch for Visual Studio which will support jQuery as well as intellisene for that. For the enthusiasts who just can&#8217;t for it, here is the way how we can start developing using jQuery with full intellisense support inside Visual Studio 2008:</p>
<p>1. Download <a title="jquery-1.2.6-vsdoc.js" href="http://jqueryjs.googlecode.com/files/jquery-1.2.6-vsdoc.js">jquery-1.2.6-vsdoc.js</a></p>
<p>2. Inside your JavaScript files, add a reference to it by placing the following line at the top of the JavaScript file:</p>
<div class="wlWriterSmartContent" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:75bfd113-eb5b-4d43-924d-27184b451c01" style="display:inline;float:none;margin:0;padding:0;">
<pre style="background-color:White;overflow:auto;">
<div><span style="color:#008000;">//</span><span style="color:#008000;">/ &lt;reference path=&quot;jquery-1.2.6-vsdoc.js&quot; /&gt;</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>That&#8217;s it. Enjoy!</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tanzimsaqib.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tanzimsaqib.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tanzimsaqib.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tanzimsaqib.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tanzimsaqib.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tanzimsaqib.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tanzimsaqib.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tanzimsaqib.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tanzimsaqib.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tanzimsaqib.wordpress.com/71/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=71&subd=tanzimsaqib&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tanzimsaqib.wordpress.com/2008/10/28/jquery-intellisense-in-visual-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d65a9fc0993ccb92b3897422dbf28d84?s=96&#38;d=identicon" medium="image">
			<media:title type="html">tanzimsaqib</media:title>
		</media:content>
	</item>
		<item>
		<title>[New Article] ASP.NET AJAX Best Practices</title>
		<link>http://tanzimsaqib.wordpress.com/2008/01/27/new-article-aspnet-ajax-best-practices/</link>
		<comments>http://tanzimsaqib.wordpress.com/2008/01/27/new-article-aspnet-ajax-best-practices/#comments</comments>
		<pubDate>Sat, 26 Jan 2008 19:23:16 +0000</pubDate>
		<dc:creator>tanzimsaqib</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://tanzimsaqib.wordpress.com/2008/01/27/new-article-aspnet-ajax-best-practices/</guid>
		<description><![CDATA[While we develop AJAX applications, we often carelessly ignore giving up bad practices, which cause effects which are not so significantly visible when the site is not so large in volume. But, it’s often severe performance issue when it is the case for sites that make heavy use of AJAX technologies such as Pageflakes, NetVibes [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=48&subd=tanzimsaqib&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>While we develop AJAX applications, we often carelessly ignore giving up bad practices, which cause effects which are not so significantly visible when the site is not so large in volume. But, it’s often severe performance issue when it is the case for sites that make heavy use of AJAX technologies such as Pageflakes, NetVibes etc. </p>
<p>There are so many AJAX widgets in one page that little memory leak issues combined may even result the site crash into very nasty “Operation aborted”. There are a lot of WebService calls, lot of iterations among collection so that inefficient coding in a whole lead to make site very heavy, browser eats up a lot of memory, requires very costly CPU cycles, and ultimately causes unsatisfactory user experience. In this article many of such issues are demonstrated in the context of ASP.NET AJAX: <a title="http://www.codeproject.com/KB/ajax/AspNetAjaxBestPractices.aspx" href="http://www.codeproject.com/KB/ajax/AspNetAjaxBestPractices.aspx" target="_blank">http://www.codeproject.com/KB/ajax/AspNetAjaxBestPractices.aspx</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/tanzimsaqib.wordpress.com/48/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/tanzimsaqib.wordpress.com/48/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tanzimsaqib.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tanzimsaqib.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tanzimsaqib.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tanzimsaqib.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tanzimsaqib.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tanzimsaqib.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tanzimsaqib.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tanzimsaqib.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tanzimsaqib.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tanzimsaqib.wordpress.com/48/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=48&subd=tanzimsaqib&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tanzimsaqib.wordpress.com/2008/01/27/new-article-aspnet-ajax-best-practices/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d65a9fc0993ccb92b3897422dbf28d84?s=96&#38;d=identicon" medium="image">
			<media:title type="html">tanzimsaqib</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET AJAX Best Practices: Introduce function delegates</title>
		<link>http://tanzimsaqib.wordpress.com/2008/01/13/aspnet-ajax-best-practices-introduce-function-delegates/</link>
		<comments>http://tanzimsaqib.wordpress.com/2008/01/13/aspnet-ajax-best-practices-introduce-function-delegates/#comments</comments>
		<pubDate>Sat, 12 Jan 2008 13:33:55 +0000</pubDate>
		<dc:creator>tanzimsaqib</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://tanzimsaqib.wordpress.com/2008/01/13/aspnet-ajax-best-practices-introduce-function-delegates/</guid>
		<description><![CDATA[Take a look at the following loop. This loop calls a function in each iteration and the function does some stuffs. Can you think of any performance improvement idea?
for(var i=0; i&#60;count; ++i)
    processElement(elements[i]);

Well, for sufficiently large array, function delegates may result in significant performance improvement to the loop.
var delegate = processElement;

for(var i=0; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=51&subd=tanzimsaqib&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Take a look at the following loop. This loop calls a function in each iteration and the function does some stuffs. Can you think of any performance improvement idea?</p>
<pre><span style="color:blue;">for</span>(<span style="color:blue;">var </span>i=0; i&lt;count; ++i)
    processElement(elements[i]);</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Well, for sufficiently large array, function delegates may result in significant performance improvement to the loop.</p>
<pre><span style="color:blue;">var </span>delegate = processElement;

<span style="color:blue;">for</span>(<span style="color:blue;">var </span>i=0; i&lt;count; ++i)
    delegate(elements[i]);</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The reason behind performance improvement is, JavaScript interpreter will use the function as local variable and will not lookup in its scope chain for the function body in each iteration.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/tanzimsaqib.wordpress.com/51/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/tanzimsaqib.wordpress.com/51/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tanzimsaqib.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tanzimsaqib.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tanzimsaqib.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tanzimsaqib.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tanzimsaqib.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tanzimsaqib.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tanzimsaqib.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tanzimsaqib.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tanzimsaqib.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tanzimsaqib.wordpress.com/51/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=51&subd=tanzimsaqib&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tanzimsaqib.wordpress.com/2008/01/13/aspnet-ajax-best-practices-introduce-function-delegates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d65a9fc0993ccb92b3897422dbf28d84?s=96&#38;d=identicon" medium="image">
			<media:title type="html">tanzimsaqib</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET AJAX Best Practices: Introduce DOM elements and function caching</title>
		<link>http://tanzimsaqib.wordpress.com/2008/01/12/aspnet-ajax-best-practices-introduce-dom-elements-and-function-caching/</link>
		<comments>http://tanzimsaqib.wordpress.com/2008/01/12/aspnet-ajax-best-practices-introduce-dom-elements-and-function-caching/#comments</comments>
		<pubDate>Fri, 11 Jan 2008 13:28:08 +0000</pubDate>
		<dc:creator>tanzimsaqib</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://tanzimsaqib.wordpress.com/2008/01/12/aspnet-ajax-best-practices-introduce-dom-elements-and-function-caching/</guid>
		<description><![CDATA[
We have seen DOM caching before and function delegation is also a kind of function caching. Take a look at the following snippet:
for(var i=0; i&#60;count; ++i)
    $get('divContent').appendChild(elements[i]); 
As you can figure out the code is going to be something like:
var divContent = $get('divContent');

for(var i=0; i&#60;count; ++i)
    divContent.appendChild(elements[i]); 
That is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=50&subd=tanzimsaqib&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /></p>
<p>We have seen DOM caching before and function delegation is also a kind of function caching. Take a look at the following snippet:
<pre><span style="color:blue;">for</span>(<span style="color:blue;">var </span>i=0; i&lt;count; ++i)
    $get(<span style="color:#a31515;">'divContent'</span>).appendChild(elements[i]); </pre>
<p>As you can figure out the code is going to be something like:
<pre><span style="color:blue;">var </span>divContent = $get(<span style="color:#a31515;">'divContent'</span>);

<span style="color:blue;">for</span>(<span style="color:blue;">var </span>i=0; i&lt;count; ++i)
    divContent.appendChild(elements[i]); </pre>
<p>That is fine, but you can also cache browser function like <code>appendChild</code>. So, the ultimate optimization will be like the following:
<pre><span style="color:blue;">var </span>divContentAppendChild = $get(<span style="color:#a31515;">'divContent'</span>).appendChild;

<span style="color:blue;">for</span>(<span style="color:blue;">var </span>i=0; i&lt;count; ++i)
    divContentAppendChild(elements[i]);   </pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/tanzimsaqib.wordpress.com/50/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/tanzimsaqib.wordpress.com/50/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tanzimsaqib.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tanzimsaqib.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tanzimsaqib.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tanzimsaqib.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tanzimsaqib.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tanzimsaqib.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tanzimsaqib.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tanzimsaqib.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tanzimsaqib.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tanzimsaqib.wordpress.com/50/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=50&subd=tanzimsaqib&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tanzimsaqib.wordpress.com/2008/01/12/aspnet-ajax-best-practices-introduce-dom-elements-and-function-caching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d65a9fc0993ccb92b3897422dbf28d84?s=96&#38;d=identicon" medium="image">
			<media:title type="html">tanzimsaqib</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET AJAX Best Practices: Problem with switch</title>
		<link>http://tanzimsaqib.wordpress.com/2008/01/11/aspnet-ajax-best-practices-problem-with-switch/</link>
		<comments>http://tanzimsaqib.wordpress.com/2008/01/11/aspnet-ajax-best-practices-problem-with-switch/#comments</comments>
		<pubDate>Thu, 10 Jan 2008 13:26:03 +0000</pubDate>
		<dc:creator>tanzimsaqib</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://tanzimsaqib.wordpress.com/2008/01/11/aspnet-ajax-best-practices-problem-with-switch/</guid>
		<description><![CDATA[Unlike .NET languages or any other compiler languages, JavaScript interpreter can not optimize switch block. Especially when switch statement is used with different types of data, it&#8217;s a heavy operation for the browser due to conversion operations occur in consequences, it&#8217;s an elegant way of decision branching though.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=49&subd=tanzimsaqib&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Unlike .NET languages or any other compiler languages, JavaScript interpreter can not optimize switch block. Especially when switch statement is used with different types of data, it&#8217;s a heavy operation for the browser due to conversion operations occur in consequences, it&#8217;s an elegant way of decision branching though.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/tanzimsaqib.wordpress.com/49/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/tanzimsaqib.wordpress.com/49/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tanzimsaqib.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tanzimsaqib.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tanzimsaqib.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tanzimsaqib.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tanzimsaqib.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tanzimsaqib.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tanzimsaqib.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tanzimsaqib.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tanzimsaqib.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tanzimsaqib.wordpress.com/49/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=49&subd=tanzimsaqib&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tanzimsaqib.wordpress.com/2008/01/11/aspnet-ajax-best-practices-problem-with-switch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d65a9fc0993ccb92b3897422dbf28d84?s=96&#38;d=identicon" medium="image">
			<media:title type="html">tanzimsaqib</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET AJAX Best Practices: Avoid using Array.length in a loop</title>
		<link>http://tanzimsaqib.wordpress.com/2008/01/10/aspnet-ajax-best-practices-avoid-using-arraylength-in-a-loop/</link>
		<comments>http://tanzimsaqib.wordpress.com/2008/01/10/aspnet-ajax-best-practices-avoid-using-arraylength-in-a-loop/#comments</comments>
		<pubDate>Thu, 10 Jan 2008 07:10:34 +0000</pubDate>
		<dc:creator>tanzimsaqib</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://tanzimsaqib.wordpress.com/2008/01/10/aspnet-ajax-best-practices-avoid-using-arraylength-in-a-loop/</guid>
		<description><![CDATA[In one of my earlier posts, I talked about DOM element accessing in a loop but forgot to talk about a very common, yet performance issue in AJAX. We often use code like the following:
var items = []; // Suppose a very long array
for(var i=0; i&#60;items.length; ++i)
    ; // Some actions
It can [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=45&subd=tanzimsaqib&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In one of my earlier posts, I talked about DOM element accessing in a loop but forgot to talk about a very common, yet performance issue in AJAX. We often use code like the following:</p>
<pre><span style="color:blue;">var </span>items = []; <span style="color:green;">// Suppose a very long array
</span><span style="color:blue;">for</span>(<span style="color:blue;">var </span>i=0; i&lt;items.length; ++i)
    ; <span style="color:green;">// Some actions</span></pre>
<p>It can be a severe performance issue if the array is so large. JavaScript is an interpreted language, so when interpreter executes code line by line, every time it checks the condition inside the loop, you end up accessing the length property every time. Where it is applicable, if the contents of the array does not need to be changed during the loop&#8217;s execution, there is no necessity to access the length property every time. Take out the length in a variable and use in every iteration:
<pre><span style="color:blue;">var </span>items = []; <span style="color:green;">// Suppose a very long array
</span><span style="color:blue;">var </span>count = items.length;
<span style="color:blue;">for</span>(<span style="color:blue;">var </span>i=0; i&lt;count; ++i)
    ; <span style="color:green;">// Some actions</span></pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/tanzimsaqib.wordpress.com/45/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/tanzimsaqib.wordpress.com/45/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tanzimsaqib.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tanzimsaqib.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tanzimsaqib.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tanzimsaqib.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tanzimsaqib.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tanzimsaqib.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tanzimsaqib.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tanzimsaqib.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tanzimsaqib.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tanzimsaqib.wordpress.com/45/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=45&subd=tanzimsaqib&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tanzimsaqib.wordpress.com/2008/01/10/aspnet-ajax-best-practices-avoid-using-arraylength-in-a-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d65a9fc0993ccb92b3897422dbf28d84?s=96&#38;d=identicon" medium="image">
			<media:title type="html">tanzimsaqib</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET AJAX Best Practices: Avoid getters, setters</title>
		<link>http://tanzimsaqib.wordpress.com/2008/01/08/aspnet-ajax-best-practices-avoid-getters-setters/</link>
		<comments>http://tanzimsaqib.wordpress.com/2008/01/08/aspnet-ajax-best-practices-avoid-getters-setters/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 08:08:02 +0000</pubDate>
		<dc:creator>tanzimsaqib</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://tanzimsaqib.wordpress.com/2008/01/08/aspnet-ajax-best-practices-avoid-getters-setters/</guid>
		<description><![CDATA[Make minimum use of setters and getters if possible. Such accessors look like .NET like kind of beautiful properties, but these create new more scopes for JavaScript interpreter to deal with. If applicable, try directly setting/getting the private variable itself rather implementing methods for getters, setters.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=47&subd=tanzimsaqib&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Make minimum use of setters and getters if possible. Such accessors look like .NET like kind of beautiful properties, but these create new more scopes for JavaScript interpreter to deal with. If applicable, try directly setting/getting the private variable itself rather implementing methods for getters, setters.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/tanzimsaqib.wordpress.com/47/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/tanzimsaqib.wordpress.com/47/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tanzimsaqib.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tanzimsaqib.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tanzimsaqib.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tanzimsaqib.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tanzimsaqib.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tanzimsaqib.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tanzimsaqib.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tanzimsaqib.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tanzimsaqib.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tanzimsaqib.wordpress.com/47/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=47&subd=tanzimsaqib&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tanzimsaqib.wordpress.com/2008/01/08/aspnet-ajax-best-practices-avoid-getters-setters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d65a9fc0993ccb92b3897422dbf28d84?s=96&#38;d=identicon" medium="image">
			<media:title type="html">tanzimsaqib</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET AJAX Best Practices: Avoid using your own method while there is one</title>
		<link>http://tanzimsaqib.wordpress.com/2008/01/06/aspnet-ajax-best-practices-avoid-using-your-own-method-while-there-is-one/</link>
		<comments>http://tanzimsaqib.wordpress.com/2008/01/06/aspnet-ajax-best-practices-avoid-using-your-own-method-while-there-is-one/#comments</comments>
		<pubDate>Sun, 06 Jan 2008 02:11:47 +0000</pubDate>
		<dc:creator>tanzimsaqib</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://tanzimsaqib.wordpress.com/2008/01/06/aspnet-ajax-best-practices-avoid-using-your-own-method-while-there-is-one/</guid>
		<description><![CDATA[Avoid implementing your own getElementById method that will cause script to DOM marshalling overhead. Each time you traverse the DOM and look for certain HTML element requires the JavaScript interpreter to marshalling script to DOM. It&#8217;s always better to use getElementById of document object. So, before you write a function, make sure similar functionality can [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=46&subd=tanzimsaqib&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Avoid implementing your own getElementById method that will cause script to DOM marshalling overhead. Each time you traverse the DOM and look for certain HTML element requires the JavaScript interpreter to marshalling script to DOM. It&#8217;s always better to use getElementById of document object. So, before you write a function, make sure similar functionality can be achieved from some other built-in functions.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/tanzimsaqib.wordpress.com/46/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/tanzimsaqib.wordpress.com/46/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tanzimsaqib.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tanzimsaqib.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tanzimsaqib.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tanzimsaqib.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tanzimsaqib.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tanzimsaqib.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tanzimsaqib.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tanzimsaqib.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tanzimsaqib.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tanzimsaqib.wordpress.com/46/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=46&subd=tanzimsaqib&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tanzimsaqib.wordpress.com/2008/01/06/aspnet-ajax-best-practices-avoid-using-your-own-method-while-there-is-one/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d65a9fc0993ccb92b3897422dbf28d84?s=96&#38;d=identicon" medium="image">
			<media:title type="html">tanzimsaqib</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET AJAX Best Practices: Careful with DOM element concatenation</title>
		<link>http://tanzimsaqib.wordpress.com/2008/01/05/aspnet-ajax-careful-with-dom-element-concatenation-2/</link>
		<comments>http://tanzimsaqib.wordpress.com/2008/01/05/aspnet-ajax-careful-with-dom-element-concatenation-2/#comments</comments>
		<pubDate>Sat, 05 Jan 2008 05:14:43 +0000</pubDate>
		<dc:creator>tanzimsaqib</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://tanzimsaqib.wordpress.com/2008/01/05/aspnet-ajax-careful-with-dom-element-concatenation-2/</guid>
		<description><![CDATA[It&#8217;s a very common bad practice. We often iterate through array, build HTML contents and keep on concatenating into certain DOM element. Every time you execute the block of code under the loop, you create the HTML markups, discover a div, access the innerHTML of a div, and for += operator you again discover the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=44&subd=tanzimsaqib&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>It&#8217;s a very common bad practice. We often iterate through array, build HTML contents and keep on concatenating into certain DOM element. Every time you execute the block of code under the loop, you create the HTML markups, discover a div, access the innerHTML of a div, and for += operator you again discover the same div, access its innerHTML and concatenate it before assigning. </p>
<pre><span style="color:blue;">function </span>pageLoad()
{
    <span style="color:blue;">var </span>links = [<span style="color:#a31515;">"microsoft.com"</span>, <span style="color:#a31515;">"tanzimsaqib.com"</span>, <span style="color:#a31515;">"asp.net"</span>];

    $get(<span style="color:#a31515;">'divContent'</span>).innerHTML = <span style="color:#a31515;">'The following are my favorite sites:'

    </span><span style="color:blue;">for</span>(<span style="color:blue;">var </span>i=0; i&lt;links.length; ++i)
        $get(<span style="color:#a31515;">'divContent'</span>).innerHTML += <span style="color:#a31515;">'&lt;a href="http://www.' </span>+ links[i] + <span style="color:#a31515;">'"&gt;http://www.' </span>+ links[i] + <span style="color:#a31515;">'&lt;/a&gt;&lt;br /&gt;'</span>;
}  </pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>However, as you know accessing DOM element is one the costliest operation in JavaScript. So, it&#8217;s wise to concatenate all HTML contents in a string and finally assign to the DOM element. That saves a lot of hard work for the browser.</p>
<pre><span style="color:blue;">function </span>pageLoad()
{
    <span style="color:blue;">var </span>links = [<span style="color:#a31515;">"microsoft.com"</span>, <span style="color:#a31515;">"tanzimsaqib.com"</span>, <span style="color:#a31515;">"asp.net"</span>];
    <span style="color:blue;">var </span>content = <span style="color:#a31515;">'The following are my favorite sites:'

    </span><span style="color:blue;">for</span>(<span style="color:blue;">var </span>i=0; i&lt;links.length; ++i)
        content += <span style="color:#a31515;">'&lt;a href="http://www.' </span>+ links[i] + <span style="color:#a31515;">'"&gt;http://www.' </span>+ links[i] + <span style="color:#a31515;">'&lt;/a&gt;&lt;br /&gt;'</span>;

    $get(<span style="color:#a31515;">'divContent'</span>).innerHTML = content;
}  </pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/tanzimsaqib.wordpress.com/44/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/tanzimsaqib.wordpress.com/44/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tanzimsaqib.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tanzimsaqib.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tanzimsaqib.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tanzimsaqib.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tanzimsaqib.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tanzimsaqib.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tanzimsaqib.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tanzimsaqib.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tanzimsaqib.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tanzimsaqib.wordpress.com/44/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=44&subd=tanzimsaqib&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tanzimsaqib.wordpress.com/2008/01/05/aspnet-ajax-careful-with-dom-element-concatenation-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d65a9fc0993ccb92b3897422dbf28d84?s=96&#38;d=identicon" medium="image">
			<media:title type="html">tanzimsaqib</media:title>
		</media:content>
	</item>
	</channel>
</rss>