title: Cleanest way to write retry logic?
body: <p>Occasionally I have a need to retry an operation several times before giving up.  My code is like:</p>
  
  <pre><code>int retries = 3;
  while(true) {
    try {
      DoSomething();
      break; // success!
    } catch {
      if(--retries == 0) throw;
      else Thread.Sleep(1000);
    }
  }
  </code></pre>
  
  <p>I would like to rewrite this in a general retry function like:</p>
  
  <pre><code>TryThreeTimes(DoSomething);
  </code></pre>
  
  <p>Is it possible in C#?  What would be the code for the <code>TryThreeTimes()</code> method?</p>