title: C# -- When will the instance of Timer be killed?
body: <p>Given the following code, the timer will trigger the PrintTimer function every one second until the user presses a key.</p>
  
  <p><strong>Question 1</strong>> When the Timer will be stopped?
  Is the Timer by default a Background thread so it will be killed after the foreground thread is terminated.</p>
  
  <p><strong>Question 2</strong>> How to programmatically stop the timer in the calling thread?</p>
  
  <pre><code>class Program
  {
      // continue to call this function until the user presses a 
      // key to terminate the application
      static void PrintTime(object state) 
      {
          Console.WriteLine("Time is: {0}",
          DateTime.Now.ToLongTimeString());
      }
      static void Main(string[] args)
      {
          TimerCallback timeCB = new TimerCallback(PrintTime);
          System.Threading.Timer t = new Timer(
              timeCB,
              null,
              0,
              1000);
          Console.WriteLine("Hit key to terminate...");
          Console.ReadLine();
      }
  }
  </code></pre>