Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 496
Jason Avatar asked Aug 14 '26 18:08

Jason


2 Answers

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.

like image 167
Marc Gravell Avatar answered Aug 17 '26 07:08

Marc Gravell


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

like image 20
tpeczek Avatar answered Aug 17 '26 08:08

tpeczek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!