1

I have an async endpoint in WebAPI .Net Core such:

[HttpGet]
public async Task<ActionResult<List<Product>>> GetProduct()
{
    await Task.Delay(10000);
    return await Task.FromResult(Ok(Products));
}

As far as I read, using async will make to reuse threads instead of blocking them. When I fire 2 separated requests from the browser my expectation is that both end simultaneously however the second one takes 20 seconds instead 10.

Is my understanding of async wrong or did I just used the wrong code sample?

[Update] The issue was trying to trigger the requests from the same browser as pointed by the post answered in the comment section.

Jero Lopez
  • 398
  • 1
  • 7
  • 18
  • 2
    Have you seen this? It may be your browser serializing the requests: https://stackoverflow.com/questions/61436547/why-does-asp-net-core-not-process-my-requests-in-parallel - what happens if you run separate concurrent `curl`/`wget` requests? – Dai Nov 21 '22 at 09:23
  • Also, according to this: https://github.com/dotnet/aspnetcore/issues/3009 - running with a debugger attached affects performance and might cause request serialization - though I presume things have improved since 2018... – Dai Nov 21 '22 at 09:25
  • You are right @Dai the issue was in the browser itself, I didn't see that previous post, thanks. – Jero Lopez Nov 21 '22 at 09:38

0 Answers0