在我的应用程序中,我有一个这样的方法,
private async Task LoadDataSetsAsyncOld()
{
if(Cache["QISRUID317"+Session.SessionID]==null)
{
using (IParameterProviderBusinessLogic parameterProviderBusiness = new ParameterProviderBusinessLogic())
{
dataSet = await parameterProviderBusiness.GetOutlierParametersAsync().ConfigureAwait(false);
using (ILocationProviderBusinessLogic _locationProviderBusinessLogic = new LocationProviderBusinessLogic((BusinessLogicBase)parameterProviderBusiness))
{
dataSet.Merge(await _locationProviderBusinessLogic.GetLocationProviderAsync());
}
using (ISamplePointProviderBusinessLogic _samplePointProviderBusinessLogic = new SamplePointProviderBusinessLogic((BusinessLogicBase)parameterProviderBusiness))
{
dataSet.Merge(await _samplePointProviderBusinessLogic.GetSamplePointProviderAsync());
}
using (IPMDOperationsProviderBusinessLogic operationsProviderDataAccess = new PMDOperationsProviderBusinessLogic((BusinessLogicBase)parameterProviderBusiness))
{
dataSet.Merge(await operationsProviderDataAccess.GetPMDOperationsAsync());
}
using (IMethodOfMeasureProviderBusinessLogic methodOfMeasureProviderBusinessLogic = new MethodOfMeasureProviderBusinessLogic((BusinessLogicBase)parameterProviderBusiness))
{
dataSet.Merge(await methodOfMeasureProviderBusinessLogic.GetMethodOfMeasureAsync().ConfigureAwait(false));
}
using (IPackerProviderBusinessLogic packerProviderBusinessLogic = new PackerProviderBusinessLogic((BusinessLogicBase)parameterProviderBusiness))
{
DataSet packerDs = await packerProviderBusinessLogic.GetPackerProviderAsync().ConfigureAwait(false);
packerDs.Relations.RemoveAt(0);
packerDs.AcceptChanges();
dataSet.Merge(packerDs);
}
using (IFilterTypeProviderBusinessLogic filterTypeProviderBusinessLogic = new FilterTypeProviderBusinessLogic((BusinessLogicBase)parameterProviderBusiness))
{
dataSet.Merge(await filterTypeProviderBusinessLogic.GetFilterTypeProviderAsync().ConfigureAwait(false));
}
using (IFilterMakerProviderBusinessLogic _filterMakerProviderBusinessLogic = new FilterMakerProviderBusinessLogic((BusinessLogicBase)parameterProviderBusiness))
{
DataSet dsMaker = await _filterMakerProviderBusinessLogic.GetFilterMakerProviderAsync();
dsMaker.Relations.RemoveAt(0);
dsMaker.AcceptChanges();
dataSet.Merge(dsMaker);
}
}
Cache["QISRUID317" + Session.SessionID] = dataSet;
}
}
我需要增强这个异步功能的性能,所以我计划使用
Task.WhenAll()
来并发执行方法中的任务。但我该怎么做,有可能吗,这是很好的做法吗?