Jason
Jason

Reputation: 135

ASP.net MVC Execute asynchronously

Is there a way to make a controller return something to the user first then execute another method?

I have a process that is very time consuming. I'd like to send back a quick JSON response to the user then process.

Upvotes: 3

Views: 366

Answers (2)

tpeczek
tpeczek

Reputation: 24125

This may serve as a good example: http://tpeczek.com/2010/07/reporting-server-side-operation.html

Upvotes: 2

Marc Gravell
Marc Gravell

Reputation: 1062502

In that scenario, you might want to consider doing the ongoing task on a worker thread. The MVC loop must complete in order to return the response to the caller. Note that background threads will not have access to the request context, so you must capture anything you need. Note also that you cannot return anything to the caller once the http context has exited - you will need the caller to call back to get any extra data.

Upvotes: 5

Related Questions