`Task.ContinueWith`参数的`antecedent`参数点?

时间:2012-05-30 19:45:06

标签: c# closures task-parallel-library

给定Task t

之间是否存在语义差异
t.ContinueWith(ante => DoSomethingWith(ante));

t.ContinueWith(ante => DoSomethingWith(t));

,假设t以后没有变异?

antecedent参数是否只存在以避免在第二个变体中分配闭包?

1 个答案:

答案 0 :(得分:5)

  

先行论证是否只存在以避免在第二个变量中分配闭包?

有效,是的。它还可以让你更简洁地写出:

 Task.Factory.StartNew( () => DoSomething())
             .ContinueWith( t => DoSomethingWith(t));

它还提供了与使用TaskFactory.ContinueWhenAllTaskFactory.ContinueWhenAny

类似的API