SHORT VERSION:
Can anyone confirm, does Task.Run/Task.WaitAll on non-async sub-functions with EF calls gain anything for ASP.NET apps?
LONG VERSION:
We have an Asp.Net WebApi service with a method which makes multiple DB calls (all using EntityFramework) to collect a set of data that all get returned into a single response object. We broke this up into a series of sub-functions, and wanted these to run in parallel (NOTE: None of these use any async calls).
To achieve some form of parallel coding, we invoke each function with Task.Run, followed by Task.WaitAll:
public ResponseObject PopulateResponseObject(int id)
{
var response = new ResponseObject();
Task<DataSetA> dataSetATask = Task.Run(() => getDataSetA(id));
Task<DataSetB> dataSetBTask = Task.Run(() => getDataSetB(id));
Task.WaitAll(dataSetATask, dataSetBTask);
response.SetA = dataSetATask.Result;
response.SetB = dataSetBTask.Result;
return response;
}
From what I've been reading, Task.Run may not gain much in an Asp.Net application, and what we have here may just result in unnecessary thread-pool overhead.
Are we wasting time writing our code this way?
UPDATE: We are familiar with the fact that EF has async versions, but there is a significant amount of code that would need to be modified. We'd like to leave these functions as-is.