如代码注释所示。我不知道为什么主线程等待"continue"。
static void Main(string[] args)
{
Task<string> antecedent = Task.Delay(5000).ContinueWith<string>(x =>
{
Console.WriteLine("return in task1 {0}", Thread.CurrentThread.ManagedThreadId);
return DateTime.Today.ToShortDateString();
});
Task<string> continuation = antecedent.ContinueWith(x =>
{
x.Wait(1000);
Console.WriteLine("return in task2 {0}{1}",Thread.CurrentThread.ManagedThreadId,x.Status);
return "Today is " + antecedent.Result;
});
Console.WriteLine("this will print before the result");
Console.WriteLine(continuation.Result); //why this waiting ?
Console.ReadKey();
}
我不知道为什么主线程等待" continue " . result ">
你还希望它做什么?它不能在存在之前打印值。
任务。内部等待任务的结果:
访问属性的get访问器会阻塞调用线程,直到异步操作完成