I'm trying to run these tasks sequentially without any blocking in the UI , however, I've test all methods that I've found but I'm still have a problem , when I get tasks runs without UI block I get a missed steps in the tasks or an infinite running of some tasks .
public void StartAsync(CancellationToken cancellationToken, string path, int i)
{
var task1 = Task.Run(() => Task1(path, step, i)); //
var task2 = Task.Run(() => Task2(cancellationToken)); // wait for task1 to complete
var task3 = Task.Run(() => Task3(cancellationToken)); // wait for task2 to complete
var task4 = Task.Run(() => Task4(cancellationToken, i)); // will call an external process ) ... wait for task3 to complete
Task.WaitAll(task1, task2, task3, task4);
}
public void AnotherTask()
{
// Some other code ( will call an external process )
}
public void RunAllTasks()
{
int step = 5;
cancellationToken = CancellationToken.None;
string path = "...\\..";
for (int i = 0;i<step;i++)
{
StartAsync(cancellationToken, string path, int i)
}
// wait for StartAsync to complete
AnotherTask();
}
private void button_Click(object sender, RoutedEventArgs e)
{
RunAllTasks();
}