async/await in MVC controller's action

后端 未结 3 1722
遇见更好的自我
遇见更好的自我 2021-02-07 12:35

I have an Index action in ASP.net MVC controller. This action, calls (among other things) a private action that do a count on a SQL table with large set of rows. Th

3条回答
  •  别那么骄傲
    2021-02-07 13:14

    This works. But is this really async?

    It is async in the fact that once you query your database (which is an IO bound operation), you free the ASP.NET Thread-Pool thread instead of using it to block until the query finishes.

    Async doesn't mean "Return this request to the caller, and i'll finish executing at a later time", which is somewhat what you're expecting. It doesn't break the HTTP request-response protocol. What you want isn't achieved by async.

    If you want the request to complete immediately, you'll need to queue it on some background thread, and push the data to the client side once the operation is complete.

提交回复
热议问题