Task & await sequentially with more than one thing

  • Thread starter Thread starter zequion1
  • Start date Start date
Z

zequion1

Guest
I have to perform an action with multiple files. The information of each file is inside a StTransfer structure. Each of the files is treated within a task to be able to display a label and a progress bar through control.invoke / BeginInvoke without UI bloqued.Although the process is asynchronous, it cannot begin processing the next file without the previous one having finished processing.I find that anything I do to wait for the above Task to finish results in UI bloqued and no Label and ProgressBar information being displayed.




// Loop Files (Resumed).

int Archive_Number = 0;
while (true)
{ Archive_Number++;

// Wait to completed the last Archive. THIS LOCKS UI.
if (Archive_Number > 0) while (!Name_TransferAdd.Cls_TransferAdd.Fcn_Transfer_async_Completed){}

// Process next File.
Fcn_Transfer(ref StTransfer, Params);
}

public static void Fcn_Transfer(ref Name_Transfer.St_Transfer StTransfer, dynamic Params = null)
{ Name_TransferAdd.Cls_TransferAdd.Fcn_Transfer_async(StTransfer, Params);
}

public static bool Fcn_Transfer_async_Completed = false;
public static async void Fcn_Transfer_async(Name_Transfer.St_Transfer StTransfer, dynamic Params = null)
{ bool Fcn_Correct = false;

Name_TransferAdd.Cls_TransferAdd.Fcn_Transfer_async_Completed = false;

// Task. Creates.
System.Threading.Tasks.Task<bool> MyTask_Transfer = System.Threading.Tasks.Task.Factory.StartNew<bool>(() => Name_TransferAdd.Cls_TransferAdd.Fcn_Transfer_(ref StTransfer, Params));


Fcn_Correct = await MyTask_Transfer;
Name_TransferAdd.Cls_TransferAdd.Fcn_Transfer_async_Completed = true;
}

Continue reading...
 
Back
Top