I was looking for this and I couldn't figure how to do it.
I have a some threats (tasks) in an App.
foreach (string targetMachine in targetMachines)
{
Task<int> task = Task.Run(() => Magic(targetMachine));
}
I created a task for every object in an array. The task returns a value. I want to process the values and act based on them. As example, if task return 0 dont do anything, if returns 1 write a log, if returns 2 run a process.
How can I acoomplish this? If I process the return values inside the foreach:
foreach (string targetMachine in targetMachines)
{
Task<int> task = Task.Run(() => Magic(targetMachine));
Task.Waitforexit()
if (task.result == 2)
{
do something
}
}
I think, task are not going to be useful and the programa will wait each task to be completed to continue.