Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't wait for longrunning operations ASP.NET MVC

We have some long running operation firing when the user does something(generating several reports). We don't want the user to wait till those reports have been generated. Is there a quick way to accomplish this without having to implement a jobscheduler? Maybe using threads like this? Or is this not safe?

    public ActionResult About()
    {
        Thread thread = new Thread(new ThreadStart(MuchWork));
        thread.Start();
        return View();
    }

    public void MuchWork()
    {
        Thread.Sleep(10000);

        Thread.Sleep(4000);
    }
like image 568
MichaelD Avatar asked Nov 06 '22 02:11

MichaelD


1 Answers

See the post The Dangers of Implementing Recurring Background Tasks In ASP.NET by Phil Haack where he describes how to hack a psuedo-job scheduler while using the IRegisteredObject interface to limit IIS/AppPool shut-down issues.

like image 117
Jon Adams Avatar answered Nov 09 '22 07:11

Jon Adams