给定一个任务t
,两者之间是否存在任何语义差异
t.ContinueWith(ante => DoSomethingWith(ante));
和
t.ContinueWith(ante => DoSomethingWith(t));
,假设 t
之后没有发生变异?
是否存在 antecedent
参数只是为了避免在第二个变体中分配闭包?
最佳答案
Does the antecedent argument exist only to avoid the allocation of a closure as in the second variant?
有效,是的。它还可以让您更简洁地编写它:
Task.Factory.StartNew( () => DoSomething())
.ContinueWith( t => DoSomethingWith(t));
它还提供了一个类似于使用 TaskFactory.ContinueWhenAll
或 TaskFactory.ContinueWhenAny
的 API。
关于c# - `antecedent` 参数的 `Task.ContinueWith` 参数点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10823181/