我只有在完成任务时打印任务结果。但是,当任务的状态出现故障时,它不允许其他任务完成并正确打印出来。有没有办法使用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
}