Cancel asynchronous postback with a long server process

I am having problems canceling the asynch postback. I have an update panel with an update progress that contains a cancel button so that the user can cancel the postback. When the user clicks a button to create a report, the update progress is displayed. A report may take a little time, because it should go through a thousand times by creating an Excel spreadsheet. If the user decides to stop the report from starting for some reason, then he can click the cancel button, which I then call abortPostBack () in javascript, which stops the progress of the update, and the page is displayed again. However, the user cannot do anything but go to another page, because the server is still processing the loop. How can I stop the server processing cycle when the user clicked the cancel button? Any help appreciated!

+4
source share
3 answers

Are you saying that a simple HTTP link is not available on the client side until the async postback is complete? If so, that sounds like a mystery, because you need to either optimize the process on the server side, or set a shorter request timeout on the server side. Either this, or redesign your user interaction to make the server-side Excel generation process asynchronous rather than synchronous so that the user does not have to wait for Excel generation to complete. You could think about it on the client side, then set a JavaScript timer to periodically request the server to find out if the file was ready, and if so, indicate that to the user and give them a link to the download file link or something kind.

Otherwise, if you could call another AJAX request, waiting for a return (that you might not hear from its sound), you can simply execute a new HTTP request that “cancels” the lengthy process. But this does not seem to work, as the server is still processing a long HTTP request. Therefore, I would prefer to explore the options in my first paragraph.

If the cancellation allowed the client to perform an asynchronous HTTP request, you can set the session state value to indicate that a cancellation was requested. Personally, I wouldn’t do that. But if you did, then your lengthy server process may periodically look for the presence of a session value. Say:

if (Session["cancel-me"] != null) { Session["cancel-me"] = null; abortThisLongProcess(); } 
+1
source

Yes, even if you go from the page using the back button of the browser, as soon as you click anything else that needs to be sent back to the server, the page freezes until a long process is completed. There seems to be no way to undo, so I have to look at redesigning the Excel generation.

0
source

I have not found a way to cancel a request that works, but there is no real reason why you cannot start a new one.

By default, ASP.Net tries (not always) to apply an exclusive lock to the session object - as soon as one page reads it every other page request that passes the same session identifier (via cookie or URL) must wait until the first page leaves from the session.

It does not matter that the client canceled the request - the server will continue to block the session until the original page completes execution.

I think the solution is to completely disconnect the ASP session . Then, when the user requests another page, it starts immediately, even if the server is still processing the old request in another thread.

0
source

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


All Articles