views:

170

answers:

3

When the user clicks on a link to generate report I make an AJAX call which generates a pdf file in the background.Now the files are huge running upto 10mb or more.So it takes some time.In the mean time the user should be able to navigate other links as if nothing has happened.So I need to implement in such a way that the pdf generation process gets started & user doesn't have to wait for the process to finish.Is this possible?I am using AJAX Pro with c# with dot net framework 2.0

The problem here is that as soon as the AJAX activity begins the browser enters into a hung stage & the user has to wait although he clicks on a different link.

A: 

Sure, but once the user navigates to another page, the Javascript that is waiting for the Ajax response is no longer running, so that request is lost. You'd have to either find a way to keep that page open (using frames or exclusively Ajaxified navigiation), or find a way to store the response and notify the user of its completion on the next page view. For instance, storing a session variable that indicates that the operation is completed, or storing it in a database with (perhaps) an "unread" boolean value.

JoshJordan
JJ
Ah, in that case you need a Worker Thread. Check out ObeseCoder's answer below, it will cause the ASP.NET runtime to spawn a separate thread to perform the operation, and let the main thread return without waiting for it to complete.
JoshJordan
+2  A: 

I would probably create a 'queue' or an 'inbox' for the user ...

start your pdf generation routine with a ThreadPool.QueueUserWorkItem (you would also need to modify your generation method to output to their inbox)

then on each http request check that inbox and notify the user of the item ... you can always poll the server on an interval or somthing

ObeseCoder
A: 

You can have asynchronous Ajax call with which you can do other tasks while response objects returns from the Ajax page. Here is some example, testAjax.aspx is the Ajax page here : http_request.onreadystatechange = function() { alertContents(http_request); }; http_request.open('GET', 'testAjax.aspx?', true); http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); http_request.send(null);

function alertContents(http_request) {//debugger; if (http_request.readyState == 4) { if (http_request.status == 200) {

             var vResult;
             vResult=http_request.responseText;    
             //Write your logic after successful Ajax call here.                   
            }
           else
            {
               alert('There was a problem with the request.');
            }
         }
Suresh Kaushik