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

Fun*_*lad 3 c# closures task-parallel-library

给定a Task t,之间是否存在语义差异

t.ContinueWith(ante => DoSomethingWith(ante));
Run Code Online (Sandbox Code Playgroud)

t.ContinueWith(ante => DoSomethingWith(t));
Run Code Online (Sandbox Code Playgroud)

,假设t以后没有变异?

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

Ree*_*sey 5

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

实际上,是的.它还可以让你更简洁地写出:

 Task.Factory.StartNew( () => DoSomething())
             .ContinueWith( t => DoSomethingWith(t));
Run Code Online (Sandbox Code Playgroud)

它还提供了类似的API来使用TaskFactory.ContinueWhenAllTaskFactory.ContinueWhenAny.