I am trying to build a page that allows the user to kick off a stored procedure and then continue to use the rest of the site without having to wait for that process to complete.
I have tried creating a background worker thread and a secondary EDMX just for this call, but currently the site is still just unresponsive while the code runs (takes one to two minutes usually).
protected void SaveReversal_Click(object sender, EventArgs e)
{
if (PeriodList.SelectedValue != "")
{
var bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler(AsyncReverseDataload_DoWork);
bw.WorkerReportsProgress = false;
bw.WorkerSupportsCancellation = false;
bw.RunWorkerAsync(Convert.ToInt32(PeriodList.SelectedValue));
}
}
private void AsyncReverseDataload_DoWork(object sender, DoWorkEventArgs e)
{
int TrackerDetailKey = (int)e.Argument;
using (AsyncEntities ar = new AsyncEntities())
{
IObjectContextAdapter dbcontextadapter = (IObjectContextAdapter)ar;
dbcontextadapter.ObjectContext.CommandTimeout = 600;
try
{
var results = ar.ReverseDataload(TrackerDetailKey);
}
catch (Exception ex)
{
Console.Write(ex.ToString());
}
}
}
How do I get this actually running so that the site remains responsive to the user after starting the execution of the stored procedure?