Voglio fare Task.WaitAll() per uscire se una qualsiasi delle attività in esecuzione genera un'eccezione, in modo che non devo aspettare per 60 secondi per finire. Come ottengo un simile comportamento? Se WaitAll() non riesce a raggiungere questo, c'è qualche altra caratteristica o soluzione C#?Come rendere Task.WaitAll() da interrompere se si verifica qualche eccezione?
Task task1 = Task.Run(() => throw new InvalidOperationException());
Task task2 = ...
...
try
{
Task.WaitAll(new Task[]{task1, task2, ...}, TimeSpan.FromSeconds(60));
}
catch (AggregateException)
{
// If any exception thrown on any of the tasks, break out immediately instead of wait all the way to 60 seconds.
}
Può uno dei downvoters spiegare? Questo è un requisito ragionevole. – usr