Skip to content

Instantly share code, notes, and snippets.

@NMZivkovic
Created June 3, 2018 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NMZivkovic/f910993e3e5f2cf3f644ac54d81034c2 to your computer and use it in GitHub Desktop.
Save NMZivkovic/f910993e3e5f2cf3f644ac54d81034c2 to your computer and use it in GitHub Desktop.
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.WhenAny(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