0

If I have a web application that wraps calls to the network and database in a Task<T> and awaits them, this should prevent the thread from blocking so it can be re-used.

However, when the IO work is carried out, is there still some thread that is blocked, so there is no real benefit to awaiting?

1 Answer 1

2

If you are just wrapping blocking calls in a Task.Run, then you are correct: there is no benefit.

However, if you are using naturally-asynchronous methods (e.g., asynchronous HttpClient/WebClient/HttpWebRequest methods and asynchronous database methods), then no threads are used by those requests, and you get a scalability benefit.

At the device driver level of Windows, all I/O is asynchronous. The synchronous APIs are just convenience wrappers. Naturally-asynchronous methods do not block a thread over the synchronous APIs; they are built on the asynchronous APIs.

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

1 Comment

This information is scattered all over MSDN and various SDKs, but some good resources are Windows Internals and CLR via C#.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.