I have to do some processing on a file loaded by the user. This process can take a long time based on the number of pages within the file. I am planning on using jQuery UIs progressbar and telling the user how many pages have been processed. However, my progress check does not return until the first ajax call is complete. Both calls complete properly are connecting to the corresponding web methods.
I researched this a little bit already, and I found this answer to another question which pretty much stated that if both calls use the Session they wont process concurrently. I only use the Session in one of the calls though.
What am I missing?
This is the initial call that starts the processing of the file. I set the UpdateProgressBar to run a second after the processing of the file starts.
setTimeout("UpdateProgressBar();", 1000);
$.ajax({
type: "POST",
async: true,
data: // my params go here
url: // path to web method
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
// Do stuff when file is finished processing
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
if (errorThrown != null)
alert(textStatus + " : " + errorThrown);
}
});
This is the UpdateProgressBar function:
function UpdateProgressBar() {
$.ajax({
type: "POST",
async: true,
data: // my params go here
url: // path to web method
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
var totalPages = parseInt($('[id$=lbl_PageCount]').text());
var pagesProcessed = result.d;
var percentProcessed = pagesProcessed / totalPages;
$('#div_ProgressBar').progressbar("value", percentProcessed);
if (pagesProcessed < totalPages)
setTimeout("UpdateProgressBar();", 800);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
if (errorThrown != null)
alert(textStatus + " : " + errorThrown);
}
});
Edit:
This is the WebMethod called by UpdateProgressBar. The other WebMethod does use Session, but as you can see this one does not. They both access a dll, however, I tried testing without using the dll for the update and it did not make a difference.
[WebMethod]
public static int CheckPDFProcessingProgress(// params go here)
{
int pagesProcessed = 1;
try
{
OrderService _orderService = new OrderService();
pagesProcessed = _orderService.GetMailingPDFPagesProcessedProgress(PersonID);
}
catch (Exception ex)
{
// log error
}
return pagesProcessed;
}
Through a little research, I was able to discover two ways to get around my problem. The main issue was Session related, however, I was not explicitly using the Session which is why it eluded me for so long.
ASP.NET pages think that they use the Session by default even if you do not use it manually. Therefore, in order for your Web Methods to behave concurrently you have to explicitly tell the WebMethods that they do not use the Session like this:
Or if you are going to have many WebMethods and are going to store them all on one page you can set the page directive to not use Session like so:
Thanks for all the help everyone!