title: System.Windows.Forms.Timer - NullReferenceException
body: <p>Is there any explanation to NullReference exception, that occured at one machine today. I cannot reproduce it at my computer....</p>
  
  <pre><code>class Test
  {
    Timer timer_;
    public void Init()
    {
      timer_ = new Timer();
      timer_.Interval = 10000;
      timer_.Tick += OnTimerTick;
      timer_.Start();
    }
  
    private void OnTimerTick(object sender, EventArgs e)
    {
      timer_.Stop();
      timer_ = null; &lt;--- Null Ref occurs
    }
  }
  </code></pre>
  
  <p>Solution based on awesome advices of Mark Hall and Rich Okelly</p>
  
  <pre><code>private void OnTimerTick(object sender, EventArgs e)
  {
      var localTimer = Interlocked.Exchange(ref timer_, null);
      if (localTimer != null)
      {
          localTimer.Stop();
          localTimer.Tick -= OnTimerTick;
          localTimer.Dispose();
  
          // doing staff
      }
  }
  </code></pre>