Created
June 25, 2014 00:15
-
-
Save isidore/dae29bb3ec2f30d1cb33 to your computer and use it in GitHub Desktop.
Async Pattern
This file contains hidden or 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
/// 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