title: C# Windows Application Timer Stops
body: <p>I have an Windows Application which uses timer like in the screen: 
  timer it's used to run a method every X minutes between 08:00:00 (Start Time) and 21:00:00 (Stop Time) 
  In the screen:
  Next download Start at: shows what time the next run will occur
  Time Left: shows the remaining time until next run will occur
  Download Interval: time span between two runs</p>
  
  <p>The method runs when the Next download Start = Current Time.</p>
  
  <p>My issue is that event that the application is open and runs, the timer just stops after a while. 
  Any ideas why this happens, is this normal or am I doing something wrong in my code (i can post it if needed but now I was just asking to see if it's normal)?
  Is there a way to prevent it or shell I create a checker and check his status regularly?</p>
  
  <p>Thanks in advance for your support!</p>
  
  <p><img src="https://i.stack.imgur.com/ifqru.jpg" alt="Main screen with the timers"> </p>
  
  <pre><code>    private System.Windows.Forms.Timer timerFrequency = new System.Windows.Forms.Timer();
  
      public void LoadGeneraInfoPanel()
     {
              timerFrequency.Interval = 1000;
              timerFrequency.Enabled = true;
              this.timerFrequency.Tick += new System.EventHandler(this.timerFrequency_Tick);
              timerFrequency.Start();
  
          }
  
    private void timerFrequency_Tick(object sender, EventArgs e)
          {
              txtGICurrTime.Text = DateTime.Now.ToString("HH:mm:ss");
  
              if (drSystemParam["Auto"].ToString() == "True" &amp;&amp; timerFrequency.Enabled)
              {
                  if (txtGIFrequency.Text.ToString() != string.Empty &amp;&amp; txtGIStopTime.Text.ToString() != string.Empty &amp;&amp; txtGIStartTime.Text.ToString() != string.Empty)
                  {
                      int iHours = Convert.ToInt32(txtGIFrequency.Text.Substring(0, 2));
                      int iMinutes = Convert.ToInt32(txtGIFrequency.Text.Substring(3, 2));
                      int iSeconds = Convert.ToInt32(txtGIFrequency.Text.Substring(6, 2));
  
                      DateTime dCurrStartTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, Convert.ToInt32(txtGIStartTime.Text.Substring(0, 2)), Convert.ToInt32(txtGIStartTime.Text.Substring(3, 2)), Convert.ToInt32(txtGIStartTime.Text.Substring(6, 2)));
                      DateTime dCurrStopTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, Convert.ToInt32(txtGIStopTime.Text.Substring(0, 2)), Convert.ToInt32(txtGIStopTime.Text.Substring(3, 2)), Convert.ToInt32(txtGIStopTime.Text.Substring(6, 2)));
  
  
                      DateTime dCurrStartDownloadTime = dCurrStartTime;
  
                      for (int j = 0; dCurrStartDownloadTime &lt; DateTime.Now &amp; dCurrStartDownloadTime &lt;= dCurrStopTime; j++)
                          dCurrStartDownloadTime = dCurrStartDownloadTime.AddHours(iHours).AddMinutes(iMinutes).AddSeconds(iSeconds);
  
                      var result = dCurrStartDownloadTime;
  
                      if (DateTime.Now &gt; dCurrStartTime &amp;&amp; DateTime.Now &lt; dCurrStopTime.AddHours(-iHours).AddMinutes(-iMinutes).AddSeconds(-iSeconds))
                      {
                          if (txtNextDownloadTime.Text == String.Empty)
                              txtNextDownloadTime.Text = result.ToString("HH:mm:ss");
  
                          TimeSpan diff = result - DateTime.Now.AddSeconds(-1);
                          txtGITimeLeft.Text = string.Format("{0}:{1}:{2}", diff.Hours.ToString().PadLeft(2, '0'), diff.Minutes.ToString().PadLeft(2, '0'), diff.Seconds.ToString().PadLeft(2, '0'));
  
                          if (DateTime.Now.ToString("HH:mm:ss") == txtNextDownloadTime.Text)
                          {
                              timerFrequency.Stop();
                              txtNextDownloadTime.Text = result.ToString("HH:mm:ss");
                              Thread.Sleep(800);
  
                              timerFrequency.Enabled = true;
                              timerFrequency.Start();
  
                              btnEecuteMethod_Click(sender, e);
                          }
                      }
                      else
                      {
  
                          result = dCurrStartTime.AddDays(1);
                          txtNextDownloadTime.Text = result.ToString("HH:mm:ss");
                          TimeSpan diff = result - DateTime.Now.AddSeconds(-1);
                          txtGITimeLeft.Text = string.Format("{0}:{1}:{2}", diff.Hours.ToString().PadLeft(2, '0'), diff.Minutes.ToString().PadLeft(2, '0'), diff.Seconds.ToString().PadLeft(2, '0'));
                      }
  
                  }
                  else
                  {
                      timerFrequency.Enabled = false;
                      timerFrequency.Stop();
                  }
              }
          }
  </code></pre>