I have a controller whose main function is to save data. The ajax call that saves this data needs to be executed quickly.
What I want to do is get the POST in the controller and spin off a background thread that will do the actual work to save the data; this would allow me to do return view() instantly. So essentially the only lag it would take is to spawn the background thread - which should be milliseconds.
I tried doing this by using a backgroundworker
public ActionResult Save(){
using (BackgroundWorker worker = new BackgroundWorker())
{
worker.DoWork += new DoWorkEventHandler(blah);
worker.RunWorkerAsync(Request.Form["data"]);
}
return View();
}
However, this call still takes a while, making me think that the background worker needs to get executed before the View is returned.
Any ideas on how to do this so that the view is returned instantly (while the background worker processes the data in the background for however long it takes)?