Created
June 3, 2018 12:10
-
-
Save NMZivkovic/d652d0961718edf2a52b14cbff26fa18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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