title: c# or vb Generic function to retry code block n number of times
body: <p>I am trying to create a generic function to which I can specify the method to be called &amp; number of times it should try getting result before it fails.</p>
  
  <p>Something like:</p>
  
  <pre><code>//3 stands for maximum number of times GetCustomerbyId should be called if it fails on first attempt.
  var result = RetryCall(GetCustomerbyId(id),3);
  </code></pre>
  
  <p>Secondly the return type should be adjusted automatically based on function it is calling.</p>
  
  <p>For example I should be able to get result from both of following function, one returns string &amp; other Customer entity.</p>
  
  <pre><code>public static string GetCustomerFullNamebyId(int id){
      return dataContext.Customers.Where(c =&gt; c.Id.Equals(id)).SingleOrDefault().FullName;
  }
  
  public static Customer GetCustomerbyId(int id){
     return dataContext.Customers.Find(id);
  }
  </code></pre>
  
  <p>Is this possible?</p>