1

I have an ASP.NET app. I'm load testing it and I managed to kind of block all threads from thread pool by running concurrent requests using an external tool. All threads are blocked due to an I/O request over the network and the method which is doing so is implemented with async and await keywords. I also have another method in another controller which just returns a string, that is, this second method does not do I/O.

The question is: isn't all requests to this non-blocking method supposed to be served even if all threads are doing asyn I/O ?

1 Answer 1

4

One can still block when calling a method that is implemented as async.

public async Task GetFooAsync() { await DoSomethingElseAsync(); } public static void MySyncMethod() { GetFooAsync().Wait(); } 

By calling .Wait(), I'm blocking the thread. It doesn't matter that the method is implemented using async/await. The same thing happens with .Result

Async methods need to be used "async all the way" - meaning the entire call stack must be async in order to be non-blocking. In an ASP.NET app, that means you are starting with an async method in your controller. If the controller method is synchronous, calling an async method will still be blocking.

See "async all the way" in this MSDN article. You may also wish to watch these essential tips for async/await on Channel 9.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually, I was testing my app on IIS hosted on Windows 7. But it turns out Windows 7 limits concurrent requests to 10. So I went to run on Windows Server 2008 and everything worked just fine. Now, all non-blocking requests run right away while the blocking ones take sometime to complete. Thanks anyway.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.