static void First() {
Console.WriteLine(2017);
Console.WriteLine("First End");
}
static void Second(Task t) {
Console.WriteLine("Second End");
}
static void Third(Task t) {
Console.WriteLine("Third Start");
Thread.Sleep(2000);
Console.WriteLine("Third End");
}
Task t = new Task(First);
Task t2 = t.ContinueWith(Second);
Task t3 = t.ContinueWith(Third);
t.Start();
while (true) {
Console.WriteLine(t.Status);
Thread.Sleep(500);
}使用new Task创建一个任务,通过这个任务的ContinueWith方法来创建连续任务,返回Task
就是在t任务完成后,t2和t3就开始异步执行
同理的,t2,t3也可以通过ContinueWith来创建他们的后续任务