A method to call another method n times or until it returns true (success). Used to talk to wireless devices in a noisy environment where each call has a chance of failure.
bool Try(uint n, Func<bool> func)
{
int i = (int)(n == 0 ? 1 : n);
do {
if (func())
return true;
i--;
}
while (i > 0);
return false;
}
Call it this way
return Try(3, ()=> { return Internal(p); });
And then it is time to level up your try policy… https://github.com/App-vNext/Polly for more goodness…
That’s some level up.
Also amusing – my mother in law’s boat was the named “Polly”. It sank.