Bon c'est un truc totallement a l'arrache et qui pourrait surement etre ameliore 100 fois mais si ca peut te depanner temporairement voila ce que je viens de faire rapidement
using System;
using System.Linq;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var array = new Task<bool>[]
{
Task.Factory.StartNew<bool>(() => TestCountBool(10, false)),
Task.Factory.StartNew<bool>(() => TestCountBool(10, false)),
Task.Factory.StartNew<bool>(() => TestCountBool(12, true)),
Task.Factory.StartNew<bool>(() => TestCountBool(10, false))
};
var task = array.WaitAnyWithCondition(t => t.Result == true);
}
private static bool TestCountBool(int nbIteration, bool result)
{
while (nbIteration-- > 0)
Task.Delay(500);
return result;
}
}
public static class TaskExtensions
{
public static Task<T> WaitAnyWithCondition<T>(this Task<T>[] tasks, Predicate<Task<T>> predicate)
{
var list = tasks.ToList();
while (list.Count > 0)
{
var id = Task.WaitAny(list.ToArray());
if (list.Count == 1 || predicate(list[id]))
return list[id];
list.RemoveAt(id);
}
return default(Task<T>);
}
}
}