Skip to content

Instantly share code, notes, and snippets.

@jpeckham
Last active April 17, 2018 01:16
Show Gist options
  • Save jpeckham/55452b5aa2752168db29abe43daf0604 to your computer and use it in GitHub Desktop.
Save jpeckham/55452b5aa2752168db29abe43daf0604 to your computer and use it in GitHub Desktop.
Illustrate use of TPL ContinueWith()
using System;
using System.Threading;
using System.Threading.Tasks;
public class Example
{
public static void Main()
{
// Execute the antecedent.
Task<string> taskA = Task.Run(() =>
{
Thread.Sleep(1000);
Console.WriteLine("taskA Task.Run()");
return "From aaskA";
}
);
// Execute the continuation when the antecedent finishes.
Task continuation = taskA.ContinueWith(antecedent =>
{
Thread.Sleep(1000);
Console.WriteLine("continuation = taskA.ContinueWith() - taskA.Result={0}", ReferenceEquals(antecedent.Result));
});
Console.WriteLine("End of App... watch threads come in.");
Console.ReadKey();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment