Last active
December 26, 2018 23:52
-
-
Save noriyukitakei/3ac6cd3a360931bdf101b5c8eeab7090 to your computer and use it in GitHub Desktop.
.NET(C#)でのHttpClientクラスの挙動
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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