ASP.NET - jQuery ajax calling a queue instead of working simultaneously?

I need to process the file uploaded by the user. This process can take a lot of time based on the number of pages in the file. I plan to use the jQuery UIs progress panel and tell the user how many pages have been processed. However, the execution check is not returned until the completion of the first ajax call. Both calls completed correctly by connecting to the appropriate web methods.

I already studied this a bit, and found this answer to another question, which pretty much stated that if both calls use a session, they will not process at the same time. I use a session in only one of the calls.

What am I missing?

This is the initial call that starts file processing. I installed UpdateProgressBar to run the second one after starting the file processing.

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 function of UpdateProgressBar:

 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 WebMethod called by UpdateProgressBar. Another WebMethod uses Session, but as you can see, this is not. They both refer to the DLL, however I tried testing without using the DLL to update, and this did not help.

 [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; } 
+4
source share
2 answers

Through a little research, I was able to find two ways to get around my problem. The main question was related to the session, however, I did not use the session explicitly, so it did not slip away for so long.

ASP.NET pages believe that they use the default session, even if you do not use it manually. Therefore, in order for your web methods to behave simultaneously, you must explicitly tell WebMethods that they are not using a session, like this:

 [WebMethod(EnableSession=false)] 

Or, if you have many WebMethods and you are going to store them on one page, you can set the page directive so that you do not use Session like this:

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

Thanks for helping everyone!

+1
source

I do not think your approach will work because you are calling setTimeout("UpdateProgressBar();", 800); as part of your successful event. A success event is fired only when an ajax request is returned. This means that you only check progress when processing is already completed.

fooobar.com/questions/643675 / ....

+1
source

Source: https://habr.com/ru/post/1401890/


All Articles