Effectively use async/await with ASP.NET Web API

前端 未结 4 1981
生来不讨喜
生来不讨喜 2020-11-30 16:40

I am trying to make use of the async/await feature of ASP.NET in my Web API project. I am not very sure whether it will make any difference in performance of my

4条回答
  •  半阙折子戏
    2020-11-30 17:19

    You are not leveraging async / await effectively because the request thread will be blocked while executing the synchronous method ReturnAllCountries()

    The thread that is assigned to handle a request will be idly waiting while ReturnAllCountries() does it's work.

    If you can implement ReturnAllCountries() to be asynchronous, then you would see scalability benefits. This is because the thread could be released back to the .NET thread pool to handle another request, while ReturnAllCountries() is executing. This would allow your service to have higher throughput, by utilizing threads more efficiently.

提交回复
热议问题