Created
December 26, 2018 23:54
-
-
Save noriyukitakei/d8775cc914937e0a27adf5eb431e71ca 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 | |
{ | |
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