Your code:
- starts thread threadpool (
Task.Run), - which will start the asynchronous I / O operation (
GetAsync) and then return to the thread pool. - When I / O is done (
await), another thread stream ( ConfigureAwait(false)) will be started , - which will start another asynchronous I / O operation to read the contents of the HTTP (
GetAsStringAsync) response and return to threadpool. - - (
await), , .
1. . , , - getBaseHttpClient threadpool, , , - / .
public static async Task<string> Get(string url)
{
var client = getBaseHttpClient();
var result = await client.GetAsync(url).ConfigureAwait(false);
if (result.IsSuccessStatusCode)
{
return await result.Content.ReadAsStringAsync();
}
return null;
}
:
var tasks = urls.Select(Get);
var responses = await Task.WhenAll(tasks);