I have read this article and from what I understand, calling .Result on the Task received from an async method should produce a deadlock on one of the controller's actions.
I have the following code on which I have tried to reproduce what should have behaved like a deadlock:
// GET api/values
[HttpGet]
public ActionResult<string> Get()
{
return GetSomeValue().Result.ToString();
}
private async Task<JObject> GetSomeValue()
{
using (var httpClient = new HttpClient())
{
var jsonString = await httpClient.GetStringAsync("https://localhost:44316/api/values");
return JObject.Parse(jsonString);
}
}
On the https://localhost:44316/api/values I have another Web Application that simply returns me a valid json.
The code runs flawlessly even though as stated in the article, it should produce a deadlock as the continuation of the GetStringAsync method should be waiting for the ASP.NET context which should be held by the first Get method (the request thread).
Why I am not able to reproduce the deadlock described in the article, what am I missing?