Answer the question
In order to leave comments, you need to log in
Why doesn't await wait for the previous await to complete?
There are 3 methods:
1. Reading from a file:
public Task LoadFromFileAsync()
{
return Task.Run(() =>
{
//загрузка данных из файла
});
}
public async Task StartCalculationAsync()
{
Task.Factory.StartNew(() => Calculation1());
Task.Factory.StartNew(() => Calculation2());
Task.Factory.StartNew(() => Calculation3());
}
public Task SaveToFileAsync()
{
return Task.Run(() =>
{
SaveToFile();
});
}
private async void button_Click(object sender, RoutedEventArgs e)
{
await LoadFromFileAsync(); //выполняется 10-15 секунд
await StartCalculationAsync(); //может выполняться часами
await SaveToFileAsync(); //выполняется 1-2 секунды
}
Answer the question
In order to leave comments, you need to log in
Here
public async Task StartCalculationAsync()
{
Task.Factory.StartNew(() => Calculation1());
Task.Factory.StartNew(() => Calculation2());
Task.Factory.StartNew(() => Calculation3());
}
Task.WaitAll
help you
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question