Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void HelloTask()
- {
- Thread.Sleep(1000);
- Console.WriteLine("Hello");
- }
- public static void WorldTask()
- {
- Thread.Sleep(1000);
- Console.WriteLine("World");
- }
- public static void ContinuationTask()
- {
- Task task = Task.Run(() => HelloTask());
- //Starts executing this after completion of HelloTask.
- //if the antecedent task produces result, it can be supplied as input to continuation taks
- task.ContinueWith((prevTask) => WorldTask());
- //Overloads
- task.ContinueWith((prevTask) => WorldTask(), TaskContinuationOptions.OnlyOnRanToCompletion);
- task.ContinueWith((prevTask) => WorldTask(), TaskContinuationOptions.OnlyOnFaulted);
- Console.WriteLine("Finished Processing. Press a key to end");
- Console.ReadKey();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement