0

Lately, I've been going back and forth between the two methods.

Youll see in the code below there is a DataTable[] data = await Task.WhenAll(datatables[])

when I utilize that code I simply assign my objects datatable properties to their corresponding array number. object.datatablePropX = data[x]

However currently I am simply awaiting each individual task with the assumption that after one await starts, it immediately goes to the next. Am I wrong in assuming this?

private static async Task<InitalizationModel> BuildInitalizationModelAsync(string comp, DataTable data, string[] allSizesWithDashes)
{
    string query = Regex.Replace(Resources.qryAllLocateOrderIDs, "@COMP", comp);
    string connection = "Server=REDACTED;Database=REDACTED;Trusted_Connection=True;";
    InitalizationModel result = new InitalizationModel();
    result.CompanyNumber = comp;
    result.AllSizesWithDashes = allSizesWithDashes;
    result.InitialData = data;
    result.LocateIdData = UtilitySqlAgent.SelectDataTable(query, connection);
    result.LocateOrderIdList = GeneralFunctions.GetAllLocateOrderIds(comp, result.LocateIdData);
    List<string> locateConstraint = GeneralFunctions.ConstraintMaker(result.LocateOrderIdList);
    Task<DataTable> LocateShipmentDataTask = LocateSqlAgent.GetAllShipmentDataAsync(locateConstraint);
    Task<DataTable> LocateOrderedItemsDataTask = LocateSqlAgent.GetAllOrderItemsAsync(locateConstraint);
    Task<DataTable> WmsShipmentDataTask = WmsSqlAgent.GetAllShipmentDataAsync(comp);
    Task<DataTable> WmsOrderedItemsDataTask = WmsSqlAgent.GetAllOrderItemsAsync(comp);
    Task<DataTable> CancellationDataTask = UtilitySqlAgent.GetAllCancellationDataAsync(comp);
    Task<DataTable> BackorderDataTask = UtilitySqlAgent.GetAllBackorderedDataAsync(comp);
    Task<DataTable> ShipMethodDataTask = UtilitySqlAgent.GetAllShipMethodDataAsync(comp);
    Task<DataTable> LocateOrderedItemsDataWithIdTask = GeneralFunctions.AddAllLocateSkuItemIDsAsync(await LocateOrderedItemsDataTask, allSizesWithDashes);
    //await Task.WhenAll(LocateShipmentDataTask, LocateOrderedItemsDataTask, WmsShipmentDataTask, WmsOrderedItemsDataTask, CancellationDataTask, BackorderDataTask, ShipMethodDataTask);
    result.LocateShipmentData = await LocateShipmentDataTask;
    result.LocateOrderedItemsData = await LocateOrderedItemsDataTask;
    result.WmsShipmentData = await WmsShipmentDataTask;
    result.WmsOrderedItemsData = await WmsOrderedItemsDataTask;
    result.CancellationData = await CancellationDataTask;
    result.BackorderData = await BackorderDataTask;
    result.ShipMethodData = await ShipMethodDataTask;
    result.LocateOrderedItemsData = await LocateOrderedItemsDataWithIdTask;
    return result;
}
boo
  • 129
  • 1
  • 4
  • 12

0 Answers0