简体   繁体   中英

Does the Web API “ApiController” steal threads from the ASP.NET thread pool when new threads are created?

As I understand it, MVC introduced AsyncController specifically to handle the issue of avoiding stealing threads from the ASP.NET thread pool when new threads are created. The new Web API does not have a similar AsyncApiController . The inheritance/implementation signature for the ApiController is also very different from Controller and AsyncController .

Question: Does Web API already handle the issue of avoiding stealing threads from the ASP.NET thread pool when creating new threads? Am I missing something new that auto-handles this?

For reference:

ApiController实现IHttpController并且该接口仅定义一个方法( ExecuteAsync ),该方法返回Task ,这意味着ApiController是Async。

MVC introduced AsyncController in MVC 2 to support asynchronous methods. Using an async controller doesn't make your code magically async. In MVC 4, the controller supports asynchronous methods, so there is no need for an AsyncController. Async methods don't replace ASP.NET or IIS threads with magical lightweight threads - When you're doing asynchronous work, you're not always using a thread. For example, when you make an asynchronous web service request, ASP.NET will not be using any threads between the async method call and the await. See my tutorial Using Asynchronous Methods in ASP.NET MVC 4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM