Try n times

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(int n, Func func)
  do {
    if (func())
      return true;
  while (n>0);
  return false;

Call it this way

return Try(3, ()=> { return Internal(p); });
Posted in Articles and tagged , .


Leave a Reply

Your email address will not be published. Required fields are marked *