I am implementing a new feature in already existing application and would like to know how best I can achieve the following:
- Create two tasks.
- Start them in parallel.
- Await and wait for one of them to complete.
- Once one of them completes, spun a timer for t seconds before returning the response. This is done because one of the task might run for a longer time than another.
I have the solution of #1 to #3 but #4.
List<Task> tasks = new List<Task>(length);
tasks.Add(CreateTask(get_data_source));
await Task.WhenAny(tasks);
I don't want to provide any timeout in #3. But I would like to wait till the completion of a task and then trigger a timer for t seconds. After t seconds, return the result (if both completed, then both else just the completed task).
await Task.Delay(...)
? – canton7