Eric Swanson
Eric Swanson

Reputation: 429

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:

Upvotes: 0

Views: 3890

Answers (2)

RickAndMSFT
RickAndMSFT

Reputation: 22800

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

Upvotes: 3

frennky
frennky

Reputation: 13934

ApiController implements IHttpController and that interface defines only one method (ExecuteAsync) which returns a Task, so that means that ApiController is Async.

Upvotes: 6

Related Questions