TaskTask1 = Task.Run(() => { return 100; }); Task1.ContinueWith((t) => { Console.WriteLine("Task Completed with result - " + t.Result); });
TaskIn this example, we first create a Task named Task1 and run it using Task.Run() method. After that, we call ContinueWith() method on Task1 and pass a lambda expression that will be executed when Task1 completes its execution. In the lambda expression, we print the result of Task1 to the console. Next, we chain another ContinueWith() method call to the first one. This time, we pass a lambda expression that will be executed after the first Continuation task completes. In this lambda expression, we simply print a message to the console. Package Library: System.Threading.Tasks.Task.ContinueWith method is a part of System.Threading.Tasks package which is a part of .NET Framework Class Library.Task1 = Task.Run(() => { return 100; }); Task1.ContinueWith((t) => { Console.WriteLine("Task Completed with result - " + t.Result); }) .ContinueWith((t) => { Console.WriteLine("Continuation Task Completed"); });