Last active
April 17, 2018 01:16
-
-
Save jpeckham/55452b5aa2752168db29abe43daf0604 to your computer and use it in GitHub Desktop.
Illustrate use of TPL ContinueWith()
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
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