title: C# - Wait and Check three times before throwing exception
body: <p>Here is the existing code. I am trying to refactor this code.</p>
  <p>What is the best way to implement this using C#</p>
  <p>The first time, I want to wait for 200ms, 2nd time 400 and 3rd time 600</p>
  <pre><code>await Task.Delay(200);
  var category = this.categoryRepository.Categories.SingleOrDefault(x =&gt; x.CategoryId == categoryId);
  if (category == null)
  {
      await Task.Delay(400);
      category = this.categoryRepository.Categories.SingleOrDefault(x =&gt; x.CategoryId == categoryId);
      if (category == null)
      {
                  await Task.Delay(600);
                  category = this.categoryRepository.Categories.SingleOrDefault(x =&gt; x.CategoryId == categoryId);
  
        if (category == null)
        {
            throw NullReferenceException;
         }
      }
    }
  </code></pre>