给定Task t
,
t.ContinueWith(ante => DoSomethingWith(ante));
和
t.ContinueWith(ante => DoSomethingWith(t));
,假设t
以后没有变异?
antecedent
参数是否只存在以避免在第二个变体中分配闭包?
答案 0 :(得分:5)
先行论证是否只存在以避免在第二个变量中分配闭包?
有效,是的。它还可以让你更简洁地写出:
Task.Factory.StartNew( () => DoSomething())
.ContinueWith( t => DoSomethingWith(t));
它还提供了与使用TaskFactory.ContinueWhenAll
或TaskFactory.ContinueWhenAny
。