title: C# Blazor: Countdown Timer
body: <p>I'm new to C# and trying to create a simple countdown timer using <code>System.Timer.Timers</code>. It didn't work as expected and I searched the internet for a solution but it didn't really fix my problem. What I want is when the user clicks the start button, it begins and displays the countdown. But although the timer kinda worked, it didn't continuously display the timer when I clicked the button once, instead, I need to click the start button many times to see the countdown number or the timer display will not change. Here's the code.</p>
  <pre><code>@page &quot;/&quot;
  
  &lt;h1&gt;Timer&lt;/h1&gt;
  
  &lt;p&gt;@counter&lt;/p&gt;
  &lt;button @onclick=&quot;StartTimer&quot;&gt;Start&lt;/button&gt;
  
  
  @code {
      private static System.Timers.Timer aTimer;
      private int counter = 60;
      public void StartTimer()
      {
          aTimer = new System.Timers.Timer(1000);
          aTimer.Elapsed += CountDownTimer;
          aTimer.Enabled = true;
      }
  
      public void CountDownTimer(Object source, System.Timers.ElapsedEventArgs e)
      {
          if (counter &gt; 0)
          {
              counter -= 1;
          }
          else
          {
              aTimer.Enabled = false;
          }
      }
  }
  </code></pre>