-1

So I was first retrieving data from a database in this manner respectively with each entity repo:

_dbset.ShareCompany.ToList();

_dbset.SourceOfIncome.ToList();

Likewise there were more db calls. Then I changed my db call to:

await _dbset.ShareCompany.ToListAsync();

await _dbset.SourceOfIncome.ToListAsync();

But I do not think that there is any performance benefit with this async call as it has to wait for the data to be retreived, which actually in turn makes it into sync call. If I have to wait for the data in order to retrieve my next data.

So if anyone could tell me when is it a good practice to use async calls and will there be any performance benefit if I use async in my second code and how?

damon shahi
  • 49
  • 1
  • 7
  • Possible duplicate of [Benefits of using async and await keywords](https://stackoverflow.com/questions/28841345/benefits-of-using-async-and-await-keywords) – Parvez Mar 10 '19 at 08:53

1 Answers1

1

Using async will release your worker thread for accepting new requests. This makes your application more responsive. If you do not use async, the worker thread is blocked and IIS will spin-up a new thread for new requests (which eventually may hamper performance of application as you can spin up only so many threads).

This is actually duplicate of this question which has already been answered.

Deepak Agarwal
  • 458
  • 1
  • 4
  • 18
  • You should mark it as duplicate rather than give an answer yourself. – Parvez Mar 10 '19 at 08:55
  • so how is there any performance benefit if i actually have to await every multiple db query call in single method (which i have to get data from multiple table )then respectively calling .tolist in sync – damon shahi Mar 10 '19 at 09:01
  • 1
    @damonshahi doing anything asynchronously does not always mean you get better performance. In this particular case, you are increasing the responsiveness of the application and avoiding thread starvation. Not every method needs to be asynchronous. Refer https://blogs.msdn.microsoft.com/seteplia/2018/01/25/the-performance-characteristics-of-async-methods/ if you want to go more deep. – Deepak Agarwal Mar 10 '19 at 09:15