Reputation: 4484
I'm trying to create a generic retry policy that passes in a object and a function to call on that object. I know it's possible with a method but I'm not sure how to include the object.
For example I have an api object that has many different methods that I'd like to pass as the action. If a certain type of exception occurs I'd need to update values in the api object.
Any ideas? thanks
public T Do<T>(Api api, Func<T> action, TimeSpan retryInterval, int retryCount = 3)
{
var exceptions = new List<Exception>();
for (int retry = 0; retry < retryCount; retry++)
{
try
{
return api.action();
}
catch (Exception ex)
{
Upvotes: 1
Views: 75