How to ask the browser not to wait for a response from the server?

I have an asp.net page that has a button that is for the user to start a calculation by calling a stored procedure in SQL Server 2005. The calculation can take up to an hour or more. When the user clicks the button to start the saved process, the browser will wait for a response from the server before completing the computation. Due to the fact that the calculation will consume a lot of time, one way or another, to ask the browser, do not wait for a response from the server until the calculation is completed?

+2


source to share


5 answers


A Response.Flush();

must do the trick. I asked a very similar question earlier on SO.Ask the browser not to wait for more content while processing is in progress , you might want to look into creating a new thread for a task like this.

Update:



From this answer downstream:

{
    System.Threading.Thread _thread = new Thread(new ThreadStart(Activity_DoWork));
    _thred.Start();
}

Activity_DoWork()
{
    //Do some things...
}

      

+1


source


My advice is to find another way to solve the problem. You don't really want to do time-consuming ASP.NET workflow tasks, but have discussed it several times before .

One of the main problems is that the workflow is being recycled by the web server, killing your work, preventing you from automatically restarting it. Consider moving the lengthy processing into a separate service application that runs in the background and waits for any signal to start processing.



Your web application can write to a message queue or touch a file on disk to wake up the service. If the task you want to run concerns only the database, you can use SQL Server Agent instead of creating your own service.

+1


source


You will probably need to use Ajax to call the function asynchronously.

Edit - Added

I found this question by following some links.

BackgroundWorker theme in ASP.NET

but I'm still sticking with my original answer, which is using Ajax.

0


source


I don't have a good link for you, but you need to create a new background thread.

0


source


If you need to call something when a process is finished or you need a result, you can use asynchronous methods.

http://www.beansoftware.com/asp.net-tutorials/asynchronous-execution-pattern.aspx

0


source







All Articles