📜  c#任务并行调用更多web api - C#代码示例

📅  最后修改于: 2022-03-11 14:48:56.410000             🧑  作者: Mango

代码示例1
foreach (var post in list)
            {
                async Task func()
                {
                    var response = await client.GetAsync("posts/" + post);
                    return await response.Content.ReadAsStringAsync();
                }

                tasks.Add(func());
            }

            await Task.WhenAll(tasks);

            var postResponses = new List();

            foreach (var t in tasks) {
                var postResponse = await t; //t.Result would be okay too.
                postResponses.Add(postResponse);
                Console.WriteLine(postResponse);
            }