1

Using MVC 4.0 Web Api I have a long running DB query which is running asynchronously and, before it completes, the controller completes its "Get" or "Post" operation. This is all as expected/wanted.

However, although it looks like MVC has sent the data back to the client nothing actually get transmitted until the long running query completes.

Is there any way I can force an early "yield" of the data to the client or even to create and transmit a new response?

4

1 に答える 1

1

The point is that I don't need the results from the query - I just want to fire and forget and it's important to return a response (saying the query has started) to the client straight away

If it is fire-and-forget and you do not need to send the result to client, simply start the task

Task.Factory.StartNew(() => db.DoThatQueryThatBroughtDownChicago());

and return a string, a JSON result saying "Task started".

于 2012-05-11T14:32:14.220 に答える