Skip to content

Instantly share code, notes, and snippets.

@prabirshrestha
Created May 16, 2012 01:49
Show Gist options
  • Save prabirshrestha/2706671 to your computer and use it in GitHub Desktop.
Save prabirshrestha/2706671 to your computer and use it in GitHub Desktop.
Task Timeout After
public async static Task<T> TimeoutAfter<T>(Task<T> task, int delay)
{
await TaskEx.WhenAny(task, TaskEx.Delay(delay));
if (!task.IsCompleted)
throw new TimeoutException("Timeout hit.");
return await task;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment