1

If I have an async task (e.g. something using an HttpClient) that times out, the task throws a TaskCanceledException.

I want to be able to retry the task. But the problem is that a Task can only be executed once.

What's the easiest way of resetting or cloning the task so I can try execute it again? Or an alternative approach so I can retry an Http timeout (other than setting a longer timeout threshold)?

Shaul Behr
  • 36,951
  • 69
  • 249
  • 387
  • Unless you need the retry to run in a new task, you could just look at implementing a [Retry Pattern](https://msdn.microsoft.com/en-gb/library/dn589788.aspx) in your current task. There are some examples on SO already - [one](http://stackoverflow.com/questions/6090026/how-to-implement-retry-logic-with-task-parallel-librarytpl) [two](http://stackoverflow.com/questions/10490307/retry-a-task-multiple-times-based-on-user-input-in-case-of-an-exception-in-task). – Equalsk Aug 17 '15 at 12:48

0 Answers0