retry after error
const int RETRIES = 3; | |
void Retry(Action f) | |
{ | |
for (int i = 0; i < RETRIES; i++) | |
{ | |
try | |
{ | |
f(); | |
} | |
catch (Exception e) | |
{ | |
if (i + 1 >= RETRIES) | |
throw e; | |
} | |
} | |
} | |
R Retry<R>(Func<R> f) | |
{ | |
for(int i=0;i<RETRIES;i++) | |
{ | |
try | |
{ | |
return f(); | |
} | |
catch(Exception e) | |
{ | |
if (i + 1 >= RETRIES) | |
throw e; | |
} | |
} | |
return default(R); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment