1

我仅在它们运行完成时打印任务结果。但是,当一个任务的状态出现故障时,它不允许其他任务完成并正确打印出来。有没有办法使用 ContinueWhenAny 或任何其他方法,即使任务出错也可以打印?

代码:

public List<Task> tasksList = new List<Task>(); // List of tasks being created

private void CheckNewResult()
{
    Task.Factory.ContinueWhenAll(tasksList.ToArray(), CompleteTasks);
}

//Only runs if all tasks Ran to Completion
private void CompleteTasks(Task[] tasks){
    if(tasks.All(t => t.Status == TaskStatus.RanToCompletion))
    {
        for(var numResults = 0; numResults < WebResult.Count; numResults++)
        {
            Print Results(numResults); //print each url result in the list
        }
    }
}


public void PrintResults(int index){
// Print the results using info within web result list
}
4

0 回答 0