我想知道如何使用Task.ContinueWith()方法调用一个Action,其中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
答案 0 :(得分:6)
Task<int> first_task = GetFirstTask();
Action<int> next_action = (result_from_first) => { //do stuff };
first_task.ContinueWith( first => next_action(first.Result) );
应该这样做