here is my code
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
Thread t1 = new Thread(DoLengthyOperation);
t1.Start();
return View();
}
public ActionResult About()
{
//Check if thread t1 is completed or not, if not keep waiting.
return View();
}
public void DoLengthyOperation()
{
Thread.Sleep(10000);
}
What i want to do is
1) Start long process in Home action, as that process does not return anything so there is no point waiting
2) in my “About” action I want to check if process started “Home” action is finished or not, if not then wait until its finish.
I have tried static instance but that won’t help with simultaneous request,
I have also tried global variable but that didn’t help as every request gets new copy of controller.
my ultimate goal is when user is looking at index page my long process should finish in the background, my process take 20 sec.
Any help would be appreciated,
Thanks
Use a Task, and store it in your session state dictionary.
Note that if your not using in process session state this will not work.