Created
April 5, 2014 14:21
-
-
Save svick/9992598 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static bool WaitAll(Task[] tasks, int timeout, CancellationToken token) | |
{ | |
var cts = CancellationTokenSource.CreateLinkedTokenSource(token); | |
foreach (var task in tasks) | |
{ | |
task.ContinueWith(t => { | |
if (t.IsFaulted) cts.Cancel(); | |
}, | |
cts.Token, | |
TaskContinuationOptions.ExecuteSynchronously, | |
TaskScheduler.Current)); | |
} | |
return Task.WaitAll(tasks, timeout, cts.Token); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment