Skip to content

Instantly share code, notes, and snippets.

@svick
Created April 5, 2014 14:21
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svick/9992598 to your computer and use it in GitHub Desktop.
Save svick/9992598 to your computer and use it in GitHub Desktop.
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