Timeout pattern on task-based asynchronous method in C#
While you can reuse WithCancellation for both cancellations and timeouts I think it’s an overkill for what you need. A simpler and clearer solution for an async operation timeout would be to await both the actual operation and a timeout task using Task.WhenAny. If the timeout task completes first, you got yourself a timeout. Otherwise, … Read more