I'm working on asp.net application to display multiple widgets on dashboard. So I'm sending an ajax call to get all the required data to the dashboard widgets.
Inside the server method there are multiple database calls to get relevant data for each widget from the database via stored procedures. Method content as follows;
List<DashboardItem> items = new List<DashboardItem>();
items.Add(GetUserList());
items.Add(GetNewsList());
items.Add(GetRecentlyViewedList());
items.Add(GetSentEmailsList());
.....
return items;
It seems this process is very slow due to the no of records in the database.
I'm trying to execute above code with Async database calls. It seems async database operations can improve this process. Can anyone help me to write async database operations? or any other suggestions to improve performance on database method calls?
awaitkeyword, then instead of returningDashboardItem[]returnTask<DashboardItem[]>, then you can create aList<Task<DashboardItem[]>>, add the returnted Tasks from these functions, then doawait Task.WaitAll(theListOfTasks)and finally use the.Resultof each task stored in the list.WaitAllis a bad idea. The whole point is to reduce blocking.await Task.WhenAll()won't block.