Let me analyze your code implementation
int x, y; ThreadPool.GetAvailableThreads(out x, out y); textBox1.Text = x.ToString()+"..."+y.ToString();
In UI Thread you can get Number of threads in ThreadPool .
Now when the following call is made:
await Task.Delay(5000);
It calls ThreadPool thread to start Delay , which will be the duration of the Async call. Now this is not the standard behavior of an Async call, as the Async call sent for IO runs on IO completion ports , associated with the queue hardware for making IO calls and the thread pool thread is not involved, but in this case you explicitly use ThreadPool thread for processing, which has nothing to do with Async per se.
This explains the reason that at the moment you go beyond the await post Delay, in ThreadPool it offers less than 1 thread, since the used thread has not yet returned to the pool, at least the pool does not take into account it is available until this time.
To do a clean Async-Await test using a standard Async call from Microsoft , such as Read / Write File Async or Network IO Async , which will not trigger a Threadpool thread, and you will see exactly the same number as expected, which will clarify Async-Await in the real sense
source share