How to implement “no wait” controller call for an

2019-09-06 21:27发布

问题:

I have a set of MVC3 controller methods that i call from my JavaScript clients that do not require returning any data. It's purely one way push of tiny data-set for further processing. Each controller call can take anywhere from 100ms to 1000ms to queue up the transaction and no data/status will be returned back to the client.

I just want the API call to return to the client right away while the processing happens in the background.

Any pointers are appreciated.

回答1:

public ActionResult AsyncAction()
{
    var MyThread = new Thread(ThreadFunction);
    MyThread.Start();

    return View("AsyncView");
}

void ThreadFunction()
{
    .
    .
    //Code for API call etc...
    .
    .
}