I want to implement re-attempt logic for X amount of times to complete a single task.
Here is what I have done
private async Task ExecuteTasks(List<Task> tasks)
{
foreach(var task in tasks)
{
// first attempt!
await task;
int failedCounter = 0;
if(task.IsFaulted)
{
while(++failedCounter <= 3)
{
// Here retry the task.
task.Start(); // this throws an exception.
}
}
}
}
Calling task.Start()
will throw an exception since the status is already faulted. How can I reset the status of a task? If this is not possible, how do I create a task from a previous failed task?