I am developing a windows forms project where I have 10 tasks and I would like to do this with async . These tasks will be displayed when the user clicks the button, and I call the async method to do this. In my code, I already have a list of parameters for these processes.
My questions:
A) How to convert my code for parallel operation of the whole process? (I would like to implement async / wait)
B) How to provide feedback to my user interface?
Below is the code I tried:
My button to call a method to start processes
private void button1_Click(object sender, EventArgs e) {
A simulation method of my process receiving a parameter
private async void ProcessObject(ProcessViewModel process) { // this is my loop scope, which I need to run in parallel { // my code is here // increment the progress of this process process.Progress++; // feedback to UI (accessing the UI controls) UpdateRow(process); } }
I tried this, but I'm not sure if this is the right way to update my user interface (grid).
private void UpdateRow(ProcessViewModel process) { dataGridView1.Rows[process.Index - 1].Cells[1].Value = process.Progress; dataGridView1.Refresh(); }
source share