Skip to content

Instantly share code, notes, and snippets.

@noriyukitakei
Created December 26, 2018 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noriyukitakei/d8775cc914937e0a27adf5eb431e71ca to your computer and use it in GitHub Desktop.
Save noriyukitakei/d8775cc914937e0a27adf5eb431e71ca to your computer and use it in GitHub Desktop.
.NET(C#)でのHttpClientクラスの挙動
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace HttpClientTest
{
class Program
{
static void Main(string[] args)
{
List<Task> tasks = new List<Task>();
for (int i = 0; i < 10; i++)
{
Task task = Task.Run(async () =>
{
using (HttpClient httpClient = new HttpClient())
{
string html = await httpClient.GetStringAsync("http://wwww.example.com/test.html");
}
});
tasks.Add(task);
}
Task t = Task.WhenAll(tasks);
t.Wait();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment