Another area where asynchronous programming is quintessential is the construction of scalable services. When dealing with many requests, it’s common to initiate the processing for a request on the thread pool. This technique is used to reduce the thread creation and deletion churn that would occur if each request would use a dedicated thread. Because thread creation is rather expensive, it’s better to reuse threads using a pool mechanism.

When using a pool, a critical question to answer is how many threads should be allocated. The ideal number of threads is quite simply the same as the amount of CPUs available. Using fewer threads causes underutilization of the system, which may be warranted if many different services are run on the ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.