Skip to content

Instantly share code, notes, and snippets.

@dataneek
Created July 16, 2018 11:59
Show Gist options
  • Save dataneek/494e57ec7463420c43eacad3b720193d to your computer and use it in GitHub Desktop.
Save dataneek/494e57ec7463420c43eacad3b720193d to your computer and use it in GitHub Desktop.
Example use of HttpClient - before and after.
namespace ConsoleApplication
{
public class Program
{
private static HttpClient client = new HttpClient();
public static async Task Main(string[] args)
{
Console.WriteLine("Starting connections");
for(int i = 0; i<10; i++)
{
var result = await client.GetAsync("http://neekgreen.com");
Console.WriteLine(result.StatusCode);
}
Console.WriteLine("Connections done");
}
}
}
namespace ConsoleApplication
{
public class Program
{
public static async Task Main(string[] args)
{
Console.WriteLine("Starting connections");
for(int i = 0; i<10; i++)
{
using(var client = new HttpClient())
{
var result = await client.GetAsync("http://neekgreen.com");
Console.WriteLine(result.StatusCode);
}
}
Console.WriteLine("Connections done");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment