Possible Duplicate:
Retry a task multiple times based on user input in case of an exception in task
I'm looking for a way to implement retry logic in TPL. I would like to have a generic function/class that will be able to return a Task which will execute a given action and in case of an exception will retry the task, up to the given retry count. I tried playing with ContinueWith and have the callback create a new task in case of an exception, but it seems that it will only work for fixed amount of retries. Any suggestions?
private static void Main()
{
Task<int> taskWithRetry = CreateTaskWithRetry(DoSometing, 10);
taskWithRetry.Start();
// ...
}
private static int DoSometing()
{
throw new NotImplementedException();
}
private static Task<T> CreateTaskWithRetry<T>(Func<T> action, int retryCount)
{
}