C# async tasks

  • Thread starter Thread starter FcabralJ
  • Start date Start date
F

FcabralJ

Guest
I'm starting learning how use async tasks and I would like to clarify two things:

- I know we should avoid async void taks unless we are in front of a event handler need. In my case, a user click a button and I need to run a bunch of methods (queries) in parallel for each block of information. Could I use it here?

- My code is saying Cannot wait void in the line "await Task.WaitAll(task1, task2, task3, task4);" What am I doing wrong here?



private async Task ExtractAllData(){
var task1 = Extraction1();
var task2 = Extraction2();
var task3 = Extraction3();
var task4 = Extraction4();

await Task.WaitAll(task1, task2, task3, task4);
}

public async Task Extraction1()
{
await ExecuteQuery("select * from Cars");
}

Continue reading...
 
Back
Top