4

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;
}
5
  • @Jim Why did you remove the ASP.Net tag and remove it from the title? Are you positive it could not be something with .NET? Commented Mar 16, 2012 at 20:29
  • I removed it from the title beacuse it doesn't belong there - that's what tags are for. I ended up removing the tag because the question address only javascript/jQuery/AJAX. I don't think someone scrolling through ASP.NET questions is looking for this kind of question, or that they will be able to answer it for you. It just doesn't seem relevant to the issue. Commented Mar 16, 2012 at 20:40
  • @Jim But I am using it on an ASP.Net website and it could be an issue involving ASP.Net could it not? Commented Mar 16, 2012 at 20:40
  • Potentially, yes, but since you barely mention ASP.NET in your question (aside from a link to another question/answer about it), it didn't seem to relevant. Commented Mar 16, 2012 at 20:43
  • Although now that I look at it more closely, you could potentially be having the same issue, or at least similar issue. Are you absolutely sure Session is only used in one of your calls? Do any of the calls (when processed on the back-end) require access to a resource that requires synchronization/can be locked? Commented Mar 16, 2012 at 20:45

2 Answers 2

1

I don't think your approach will work because you call setTimeout("UpdateProgressBar();", 800); as part of your success event. The success event is only triggered when the ajax request has returned. This means you are only checking for progress when the processing has already completed.

Take a look at this StackOverflow answer.

Sign up to request clarification or add additional context in comments.

2 Comments

It is called on the success of the first check of the processing progress. I dont want it to run again until the first check has returned. It is initially called as a timeout to run a second after processing starts
Ok, i didn't notice the first call to UpdateProgressBar at the top. You should probably be using setInterval("UpdateProgressBar()", 800); instead so you don't need to keep calling it in the success event.
1

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:

[WebMethod(EnableSession=false)]

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:

<%@ Page Async="true" EnableSessionState="False" %>

Thanks for all the help everyone!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.