I have a asp.net page that with a button which is for user to run a calculation by calling a stored proc in SQL Server 2005. The calculation may take up to an hour or more. When user click on the button to run the stored proc...the browser will wait for the response from the server until the calculation is complete. Because of the calculation will consume lots of time, so is there anyway to ask the browser do not wait for the response from server until the calculation is completed?
You'd probably need to use Ajax to call the function asynchronously.
Edit - added
I found this question by following some of the links.
http://stackoverflow.com/questions/57845/backgroundworker-thread-in-asp-net/57891#57891
but I still stand by my original answer, which is to use Ajax.
A Response.Flush();
should do the trick. I asked a very similar question earlier here on SO, Instruct the browser not to wait for more content while processing continues, you may want to look into spawning a new thread for a task like that.
Update:
From this answer on threading:
{
System.Threading.Thread _thread = new Thread(new ThreadStart(Activity_DoWork));
_thred.Start();
}
Activity_DoWork()
{
//Do some things...
}
I don't have a good link for you to follow, but spawning a new background thread is the thing to do.
If you need to call something when the process is finished or you need a result then you could use asynchronous methods.
http://www.beansoftware.com/asp.net-tutorials/asynchronous-execution-pattern.aspx
My advice is to find some other way to solve the problem. You really do not want to execute long running tasks in the ASP.NET worker process, as discussed several times before.
One of the major problems is the risk of the worker process gets recycled by the web server, killing your job without giving you any chance to automatically restart it. Consider moving the long running processing to a seperate service application, which runs in the background and waits for some signal to start processing.
Your web application could write to a message queue or touch a file on disk to wake up the service. If the task to be run is only dealing with the database, you could use the SQL Server Agent, rather than building your own service.