17 using CancellationTokenSource Tcs =
new();
18 Task CompletedTask = await Task.WhenAny(task, Task.Delay(timeout, Tcs.Token));
19 if (CompletedTask == task)
24 throw new TimeoutException();
An extensions class for the Task class.
static async Task< TResult > TimeoutAfter< TResult >(this Task< TResult > task, TimeSpan timeout)
Helper method to wait for a task to complete, but with a given time limit.