I'm working in a simple timeout code for my http requests. I got this
private async Task<HttpResponseMessage> ExecuteIOTask(Task<HttpResponseMessage> ioTask, int timeout)
{
var timeoutTask = await Task.WhenAny(Task.Delay(timeout), ioTask);
if (ioTask.IsCompleted)
return ioTask.Result;
throw new TimeoutException();
}
After IsCompleted, is there any difference using Result
vs await
? The task is already completed at that instance, so I think the performance should be the same. But i'm a little concern about the exception handling. I think Result
is not going to propagate the exceptions but await
will.
Is this correct?