Skip to content

Instantly share code, notes, and snippets.

@noriyukitakei
Last active December 26, 2018 23:52
Show Gist options
  • Save noriyukitakei/3ac6cd3a360931bdf101b5c8eeab7090 to your computer and use it in GitHub Desktop.
Save noriyukitakei/3ac6cd3a360931bdf101b5c8eeab7090 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
{
private static readonly HttpClient httpClient = new HttpClient();
static void Main(string[] args)
{
List<Task> tasks = new List<Task>();
for (int i = 0; i < 10; i++)
{
Task task = Task.Run(async () =>
{
string html = await httpClient.GetStringAsync("http://www.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