title: Implement c# timeout
body: <p>Is it bad practice to use such while loop?
  Maybe it is better to use Stopwatch, or maybe this solution has some pitfalls?</p>
  
  <pre><code>    public void DoWork()
      {
          //do some preparation
          DateTime startTime = DateTime.Now;
          int rowsCount = 0;
          int finalCount = getFinalCount();
          do
          {
              Thread.Sleep(1000);
              rowsCount = getRowsCount(); // gets rows count from database, rows are added by external app.
          } while (rowsCount &lt; finalCount &amp;&amp; DateTime.Now - startTime &lt; TimeSpan.FromMinutes(10));
  
      }
  </code></pre>
  
  <p>I saw this article <a href="https://stackoverflow.com/questions/299198/implement-c-generic-timeout">Implement C# Generic Timeout</a>,
  but it is too complex to use in simple scenarios - you need to think about sync of threads, is it proper to abort them or not and so on.</p>