I am working with ASP.NET Core MVC (.NET 6), had read many example about PostAsJsonAsync() method work in async/await, and doesn't recommend use the Result property of the task because it is blocking.
I am curious is it really that bad if running ASP.NET server-side application?
For example - web Controller
public IActionResult Authorized([Required] string code)
{
if (ModelState.IsValid)
{
var payLoad = (dynamic)new JsonObject();
payLoad.code = code;
var content = new StringContent(payLoad.ToString(), Encoding.UTF8, "application/json");
using HttpClient httpClient = new HttpClient();
var result = httpClient.PostAsJsonAsync("https://www.apiserver.com", content).Result;
string responseBody = result.Content.ReadAsStringAsync().Result;
}
return View();
}
The code is clean and straight forward. If I change to Async/Await
var response = await client.SendAsync(request);
var content = await response.Content.ReadAsStringAsync();
And I have to change the IActionResult to async Task<IActionResult>,
Had do a load test on 100 requests per minutes to compare Sync or Async, it seem not much performance gain, so what is beneficial?
If .Result is so bad, why Microsoft not obsolete this?