I have the below code in a ASP.Net web forms page which basically checks if some value is in cache and if not it calls a method which gets the data and then stores it in Cache. The method which gets the data is below
ChartRenderingHelper.GenerateBidsStatusCreated(currYear.ToString(), currQuarter.ToString(), currYearType.ToString())
calls a Stored proc using EF and these 3 calls all call separate SP's..Now I am doing it sequentially so if each SP takes 5 seconds the total operation takes 15..I was thinking of using some Tasks to run these in parallel but not sure how I can change my current code to do that.
bidsCreated.Value = DashboardCacheHelper.IsIncache(bidsCreatedKey, useCaching) ? DashboardCacheHelper.GetFromCache(bidsCreatedKey) : (string)DashboardCacheHelper.SaveCache(bidsCreatedKey, JsonConvert.SerializeObject(ChartRenderingHelper.GenerateBidsStatusCreated(currYear.ToString(), currQuarter.ToString(), currYearType.ToString())), DateTime.Now.AddDays(cacheDays));
bidsSubmitted.Value = DashboardCacheHelper.IsIncache(bidsSubmittedKey, useCaching) ? DashboardCacheHelper.GetFromCache(bidsSubmittedKey) : (string)DashboardCacheHelper.SaveCache(bidsSubmittedKey, JsonConvert.SerializeObject(ChartRenderingHelper.GenerateBidsStatusSubmitted(currYear.ToString(), currQuarter.ToString(), currYearType.ToString())), DateTime.Now.AddDays(cacheDays));
bidsClosed.Value = DashboardCacheHelper.IsIncache(bidsClosedKey, useCaching) ? DashboardCacheHelper.GetFromCache(bidsClosedKey) : (string)DashboardCacheHelper.SaveCache(bidsClosedKey, JsonConvert.SerializeObject(ChartRenderingHelper.GenerateBidsStatusClosed(currYear.ToString(), currQuarter.ToString(), currYearType.ToString())), DateTime.Now.AddDays(cacheDays));
How can I do these 3 assignments in parallel? Using TPL I know we can run methods in parallel
Parallel.Invoke(() => DoSomeWork(), () => DoSomeOtherWork());
Is this the recommended approach and if I have say 12 operations that need to run in parallel all calling SQL Stored Procs using EF would that be an issue in performance.