Using TPL, i have multiple tasks set up (created dynamically, could be a large number), each returns a bool, i want to check if all task return values are true. how would i do this? is it possible? if not, is it possible to pass in a shared object to each task and have the tasks update this object?
EDIT: This would be an example of my task. ProcessEntity returns a bool. Now I have multiple of these tasks created and executed. I need to check that all the results are true.
private Task<bool> CreateTask(MyEntity entity, Action onStart, Action onComplete)
{
return (new Task<bool>(
() =>
{
onStart.Invoke();
var result = false;
try
{
result = ProcessEntity(myEntity);
}
catch (Exception ex)
{
}
onComplete.Invoke();
return result;
})
);
}
for (int i = 0; i < counter; i++)
{
CreateTask(entities[i], () => _taskCounter++, () => _taskCounter--).Start();
}
So at this point I need to continue execution of other code and that must only happen if all tasks returned true.