title: Timing a method to repeat every N seconds for M hours
body: <p>So I have a method that has to run every 30 seconds for upto 2 hours.</p>
  
  <p>My code is:</p>
  
  <pre><code>private void btnJSON_Click(object sender, RoutedEventArgs e)
  {
      Task.Factory.StartNew(() =&gt;
      {
          //Timing Logic
          var geTimerDelay = 2;
          Stopwatch s = new Stopwatch();
          s.Start();
          while (s.Elapsed &lt; TimeSpan.FromHours(geTimerDelay))
          {
  
              Stopwatch s30 = new Stopwatch();
              s30.Start();
              while (s.Elapsed &lt; TimeSpan.FromSeconds(30))
              {
                  //Method To Run
              }
              s30.Stop();
          }
          s.Stop();
      });
  }
  </code></pre>
  
  <p><strong>Am I doing it correctly (that is achieving the time-gap as mentioned) or is there a correct and/or more time - precise way to do it?</strong></p>
  
  <p>I need to know because I am access data from specific urls and sometimes I am getting null values, maybe due to too frequent access.</p>
  
  <p>Thanks.</p>
  
  <p>EDIT: <a href="https://stackoverflow.com/questions/29498525/stopwatch-or-timer">This</a> gave me an idea of not using a timer, for no specific reason.</p>