I'm testing out the impact of using async and await as I understand it is supposedly able to run multiple calls by not blocking a thread.
I used this link as my reference
The following is my code on the controller :
[Route("api/email")]
public class EmailController : Controller
{
private ContentManagement _contentManagement;
public EmailController(ContentManagement contentManagement)
{
_contentManagement = contentManagement;
}
[HttpGet("async")]
public async Task<IActionResult> GetAsync()
{
DateTime cur = DateTime.Now;
var name = await _contentManagement.GetNameAsync();
return Ok($"Value : {name} \nStarted : {cur.TimeOfDay}\n Ended : {DateTime.Now.TimeOfDay}");
}
[HttpGet("normal")]
public IActionResult Get()
{
DateTime cur = DateTime.Now;
var name = _contentManagement.GetName();
return Ok($"Value : {name} \nStarted : {cur.TimeOfDay}\n Ended : {DateTime.Now.TimeOfDay}");
}
}
The contentManagement class is exactly the same as provided in the link above.
I find that when I call the async web apis simultaneously, they perform exactly the same as the sync web api by performing the tasks sequentially.
Here are my results :
Anyone can provide feedback if I'm missing something or did something wrong?
UPDATE: - So when I tried it on two devices, one on my computer and another on my phone, it seems that they run simultaneously (regardless if it's an async / await or just a normal sync method); - If it's on the same device, they run sequentially (as shown in the image above)
