Skip to content

Instantly share code, notes, and snippets.

@isidore
Created June 25, 2014 00:15
Show Gist options
  • Save isidore/dae29bb3ec2f30d1cb33 to your computer and use it in GitHub Desktop.
Save isidore/dae29bb3ec2f30d1cb33 to your computer and use it in GitHub Desktop.
Async Pattern
/// DON'T USE ASYNC
[TestMethod]
public async Task TestHttp()
{
var response = await new HttpClient().GetAsync("http://www.google.com/");
Assert.AreEqual(response.StatusCode, HttpStatusCode.OK);
}
/// Prefer to use .Result
[TestMethod]
public void TestHttp()
{
var response = new HttpClient().GetAsync("http://www.google.com/").Result;
Assert.AreEqual(response.StatusCode, HttpStatusCode.OK);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment