async Task RunWorkflow() | |
{ | |
var stopwatch = Stopwatch.StartNew(); | |
// Task 1 takes 2 seconds to be done. | |
var task1 = Task.Delay(2000) | |
.ContinueWith(task => Completed("Task 1", stopwatch.Elapsed)); | |
// Task 2 takes 3 seconds to be done. | |
var task2 = Task.Delay(3000) | |
.ContinueWith(task => Completed("Task 2", stopwatch.Elapsed)); | |
// Task 3 takes 1 second to be done. | |
var task3 = Task.Delay(1000) | |
.ContinueWith(task => Completed("Task 3", stopwatch.Elapsed)); | |
await Task.WhenAll(task1, task2, task3); | |
// Print the final result. | |
Completed("Workflow: ", stopwatch.Elapsed); | |
stopwatch.Stop(); | |
} | |
void Completed(string name, TimeSpan time) | |
{ | |
Console.WriteLine($"{name} : {time}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment