C# 延续任务

可以使用 Task 对象的特性来处理任务的延续。GreetingAsync 方法返回一个 Task<string>对象。该 Task<string>对象包含任务创建的信息,并保存到任务完成。Task 类的 ContinueWith 方法定义了任务完成后就调用的代码。指派给ContinueWith 方法的委托接收将已完成的任务作为参数传入,使用 Result 属性可以访问任务返回的结果:.

private static void CallerwithContinuationTask(){  TraceThreadAndTask("started CallerWithContinuationTask");  var t1 = GreetingAsync("Stephanie");  t1.ContinueWith(t =>  {    string result = t.Result;     Console.WriteLine(result);    TraceThreadAndTask("ended CallerWithContinuationTask");  }) ;}