public static async Task Go(int loops) { Debugger.Break(); var requests = new List <Task <string> >(loops); for (Int32 n = 0; n < requests.Capacity; n++) { requests.Add(Part3_NamedPipeClient.IssueClientRequestAsync("http://Wintellect.com", "Request #" + n)); } string[] responses = await Task.WhenAll(requests); Debugger.Break(); for (Int32 n = 0; n < responses.Length; n++) { Console.WriteLine(responses[n]); } }
public static async Task Go(int loops) { var requests = new List <Task <string> >(loops); for (Int32 n = 0; n < requests.Capacity; n++) { requests.Add(Part3_NamedPipeClient .IssueClientRequestAsync("localhost", "Request #" + n)); } // Continue as EACH task completes while (requests.Count > 0) { var responseTask = await Task.WhenAny(requests); requests.Remove(responseTask); Console.WriteLine(responseTask.Result); } }