c# - `antecedent` 参数的 `Task.ContinueWith` 参数点?

标签 c# closures task-parallel-library

给定一个任务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.ContinueWhenAllTaskFactory.ContinueWhenAny 的 API。

关于c# - `antecedent` 参数的 `Task.ContinueWith` 参数点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10823181/

相关文章:

c# - 如何在数据 GridView 中查看 MS Access 中的数据?

c# - 在更新表或将数据插入表之前将字符串转换为十进制

javascript - 试图理解闭包。有人可以引导我完成这段代码吗?

JavaScript Closure - 帮助我理解为什么内部函数的返回值不返回

javascript - jquery animate 回调直到最终循环才执行

c# - Parallel.forEach(DataTable.AsEnumerable() 线程安全吗

C# Async ApiController 过早关闭 OutputStream

c# - 在 .NET 中寻找用于并发的静态代码分析工具,如 CheckThread for java

c# - 在 HttpListener、GetContextAsync 之后使用 Task.Run 或 ContinueWith?

javascript - 在 asp.net 中使用 javascript 将字符串转换为日期时间