Task.WhenAll() - does it create a new thread?

Viewed 6868

According to MSDN:

Creates a task that will complete when all of the supplied tasks have completed.

When Task.WhenAll() is called, it creates a task but does that necessarily mean that it creates a new thread to execute that task? For example, how many threads are created in this console application below?

class Program
{
    static void Main(string[] args)
    {
        RunAsync();
        Console.ReadKey();
    }

    public static async Task RunAsync()
    {

        Stopwatch sw = new Stopwatch();
        sw.Start();
        Task<string> google = GetString("http://www.google.com");
        Task<string> microsoft = GetString("http://www.microsoft.com");
        Task<string> lifehacker = GetString("http://www.lifehacker.com");
        Task<string> engadget = GetString("http://www.engadget.com");

        await Task.WhenAll(google, microsoft, lifehacker, engadget);
        sw.Stop();
        Console.WriteLine("Time elapsed: " + sw.Elapsed.TotalSeconds);
    }

    public static async Task<string> GetString(string url)
    {
        using (var client = new HttpClient())
        {
            return await client.GetStringAsync(url);
        }
    }
}
1 Answers
Related