C# Task.continuewith 依赖于之前的 Task.Result

标签 c# asynchronous task

我想知道您将如何使用调用 Action 的 Task.ContinueWith() 方法,其中 int 是第一个任务的结果。这是相同的代码示例:

Task<int> first_task = GetFirstTask();
Action<int> next_action = (result_from_first) => { //do stuff };
first_task.ContinueWith( () => next_action(first_task.Result) );

错误:

Error   81  Delegate 'System.Action<System.Threading.Tasks.Task<int>>' does not take 0 arguments

最佳答案

Task<int> first_task = GetFirstTask();
Action<int> next_action = (result_from_first) => { //do stuff };
first_task.ContinueWith( first => next_action(first.Result) );

应该这样做

关于C# Task.continuewith 依赖于之前的 Task.Result,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24663642/

相关文章:

c# - 创建没有命名空间声明的 XML 元素

c# - 在 mac/win 上以编程方式访问 chrome 和 firefox 密码?

c# - 许可证执行系统在调用 wkhtmltopdf.exe 时被篡改 - win server 2008

c# - 计算数据网格上的行并将其添加为新列

python - 如何对协程进行限速,限速后重新调用协程?

C# 命名任务 正确的方法是什么?

javascript - 将异步调用的数据存储到 AngularJS 中的变量

javascript - NodeJS 运行系列 - 它实际上是做什么的?

android - 如何在不清除整个后台堆栈的情况下关闭任务中的所有 Activity ?

java - JavaFX-无法再次运行任务