using System.Threading.Tasks;
public static void Main()
Task t1 = new Task(DoOnFirst);
Task t2 = t1.ContinueWith(DoOnSecond);
Task t3 = t1.ContinueWith(DoOnSecond);
Task t4 = t2.ContinueWith(DoOnSecond);
Task t5 = t1.ContinueWith(DoOnError, TaskContinuationOptions.OnlyOnFaulted);
Console.WriteLine("DoOnFirst doing some task {0}", Task.CurrentId);
static void DoOnSecond(Task t)
Console.WriteLine("DoOnSecond task {0} finished", t.Id);
Console.WriteLine("DoOnSecond this task id {0}", Task.CurrentId);
Console.WriteLine("DoOnSecond do some cleanup");
static void DoOnError(Task t)
Console.WriteLine("DoOnError task {0} had an error!", t.Id);
Console.WriteLine("DoOnError my id {0}", Task.CurrentId);
Console.WriteLine("DoOnError do some cleanup");