Last active
March 19, 2020 07:15
-
-
Save huanlin/7fc018f481fc7fb033c9ffd11138bb64 to your computer and use it in GitHub Desktop.
Demo deadlock with getting async result in ASP.NET 4.x
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
public class DemoDeadlockController : ApiController | |
{ | |
[HttpGet] | |
public HttpResponseMessage DownloadPage() | |
{ | |
var task = MyDownloadPageAsync("https://www.huanlintalk.com"); | |
var content = task.Result; | |
return Request.CreateResponse($"網頁長度: {content.Length}"); | |
} | |
private static HttpClient _httpClient = new HttpClient(); | |
private async Task<string> MyDownloadPageAsync(string url) | |
{ | |
string content = await _httpClient.GetStringAsync(url); | |
return content; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment