title: Run code in the background, Windows Forms Timer
body: <p>I'm trying to use the timer class as stated in this question:</p>
  <blockquote>
  <p><a href="https://stackoverflow.com/questions/12535722/what-is-the-best-way-to-implement-a-timer">What is the best way to implement a &quot;timer&quot;?</a></p>
  </blockquote>
  <pre><code>using System.Timers;
  </code></pre>
  <p>_</p>
  <pre><code> System.Timers.Timer aTimer = new System.Timers.Timer();
   aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
   aTimer.Interval = 1;
   aTimer.Enabled = true;
   aTimer.Start();
   void OnTimedEvent(object source, ElapsedEventArgs e)
   {
   Text += &quot;hello world&quot;;
   }
  </code></pre>
  <p>but it not only doesn't work, it also gives an error message in Microsoft Visual Studio when I close the application.</p>
  <p><a href="https://i.stack.imgur.com/P7XRg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P7XRg.png" alt="enter image description here" /></a></p>
  <blockquote>
  <p>The target process was terminated with code 0 by evaluating the function 'System.AppDomain.IsAppXModel'.</p>
  <p>If the problem happens regularly consider disabling the Tools -&gt; Options, &quot;Debugging -&gt; General -&gt; Enable property evaluation and other implicit function calls&quot; or change the code to disable evaluation of this method. See help for information on doing this.</p>
  </blockquote>