Read Time2 Minute, 0 Second

Once i was stuck with a process(long running for loop) at server side in asp.net, hence i thought to change code in such a way that some how i got intimation about how much work that process has done.

I have decided to make two pages,
one page when called starts a long running process,
And, Second page i call frequently from java script(with jQuery.ajax()), and that page gives me status (% of work done) of process start by first page.

Following is two JavaScript functions,

That uses JQuery’s Ajax request,

First function is intended to update page with some kind of intimation to user (like 30% work has been done).

function getFrequentUpdate() {

jQuery.ajax({
url: “getFrequentUpdate.aspx?” + “tmp=” + Math.random() * 1000,
async: true,
type: ‘GET’,
cache: false,
success: function(msg) {
jQuery(“#divMsg”).html(” Current Progress is: ” + msg);

var runtimeProgress = (parseInt(msg) * 100) / parseInt(jQuery(“#hdTotalObject”).val());
runtimeProgress = Math.ceil(parseFloat(runtimeProgress));
runtimeProgress = parseFloat(runtimeProgress) * 10;

jQuery(“#divProgress”).css(‘width’, runtimeProgress + ‘px’);
}
});

}

Second function calls a page that starts a long running process.

function startLongRunningProcess() {
getFrequentUpdate();
myintval = setInterval(‘getFrequentUpdate()’, myDelay);

jQuery.ajax({
url: “someProcess.aspx?” + “tmp=” + Math.random() * 1000,
async: true,
type: ‘GET’,
cache: false,
success: function(msg) {

window.clearInterval(myintval);
jQuery(“#lblStartBackup”).html(“Process has been completed successfully.”);

}
});

}

Main challenging task is to update page with % of work long running process has done.

Here, I have first tried with using session variable, but later I came to know that somehow, when, I tried to run multiple pages together, and if they access SESSION variable, one of process was stopped, until second one has finished.

To overcome that issue, I have used a class in “App_Code” folder with STATIC VARIABLE that can be used application wide:

static public int MyStatusVariable = 0;

In my case, my long running process was updating above server variable and first Ajax function was fetching it frequently, with interval specified with in

myintval = setInterval(‘ getFrequentUpdate ()’, 2000);


NOTE : Also visit www.dhanashree.com


If you are in need of any
Web Development feel free to Inquire us . Dhanashree Inc. Expertise in Asp.net Development, Php Development,
Website designing
, Open Source customisation. Dhanashree Inc can be our offshore development company /
outsourcing web development company, hire dedicated web programmers.


Above information is for knowledge sharing if you have problem / issue / suggestion please intimate us with details for proper and prompt action.

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

Close