Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Net.Http;
- using System.Threading;
- namespace HttpClientTest
- {
- class Program
- {
- static void Main(string[] args)
- {
- while (Check())
- {
- Console.WriteLine("can't start still here");
- Thread.Sleep(10);
- }
- Console.WriteLine("Starting connections");
- for (int i = 0; i < 10; i++)
- {
- using (var client = new HttpClient())
- {
- //client.DefaultRequestHeaders.Connection.Add("close");
- var result = client.GetAsync("http://aspnetmonsters.com").Result;
- Console.WriteLine(result.StatusCode);
- }
- }
- Console.WriteLine("Connections done");
- var start = DateTime.Now;
- while (Check())
- {
- Console.Write(".");
- Thread.Sleep(10);
- }
- //not the best benchmark but anyway
- var end = DateTime.Now;
- Console.WriteLine();
- Console.WriteLine("total time: {0:N} milliseconds", (int)end.Subtract(start).TotalMilliseconds);
- Console.ReadKey();
- }
- private static bool Check()
- {
- var proc = new Process
- {
- StartInfo = new ProcessStartInfo
- {
- FileName = "netstat.exe",
- Arguments = "-n -p TCP",
- UseShellExecute = false,
- RedirectStandardOutput = true,
- CreateNoWindow = true
- }
- };
- proc.Start();
- while (!proc.StandardOutput.EndOfStream)
- {
- string line = proc.StandardOutput.ReadLine();
- if (line != null && line.Contains("23.101.203.214")) return true;
- }
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement