title: C# Timer Skips Code
body: <p>I tell the Timer to start in the constructor. It starts, but when it reaches its Timer.Elapsed event it only runs the first if statement in the method. I've checked to see if <code>isWatching</code> is true, and it is, but it still skips it entirely. It doesn't even reach the <code>if(isWatching)</code> line.</p>
  
  <p>Code:</p>
  
  <p><strong>MainWindow.xaml.cs</strong>:</p>
  
  <pre><code>public partial class MainWindow : Window
  {   
      public SessionManager SM { get; private set; }
  
      public MainWindow()
      {
          SM = new SessionManager();
          SM.NewDayEvent += SplitSession;
          ///code
      }
  }
  </code></pre>
  
  <p><strong>SessionManager.cs</strong> (Some variables have been omitted from this post):</p>
  
  <pre><code>public class SessionManager : INotifyPropertyChanged
  {
      public delegate void NewDayEventHandler(object sender, EventArgs ea);
      public event NewDayEventHandler NewDayEvent;
  
      private bool _isWatching;
      private Timer _timer;
      private bool isWatching
      {
          get
          {
              return _isWatching;
          }
          set
          {
              _isWatching = value;
              if (!_isWatching)
              {
                  _clockWatch.Stop();
              }
              else
              {
                  _clockWatch.Start();
              }
          }
      }
      #endregion
  
  
      public SessionManager()
      {
          _clockWatch = new Stopwatch();
          _timer = new Timer(1000);
          _timer.Elapsed += timerElapsed;//focus on this here
  
          _isWatching = false;
          current_time = new DateTime();
          CurrentTime = DateTime.Now;
          _timer.Start();
      }
  
      public void timerElapsed(object sender, ElapsedEventArgs e)
      {
          CurrentTime = DateTime.Now;
          if (CurrentTime.TimeOfDay == TimeSpan.Parse("9:32 AM") &amp;&amp; NewDayEvent != null)
          {
              NewDayEvent(this, new EventArgs());
          }
          if (isWatching)
          {
              if (CurrentSession != null)
              {
                  //update the timespent variable of the current timeEntry
                  if (CurrentSession.currentTimeEntry != null)
                  {
                      CurrentSession.currentTimeEntry.TimeSpent = _clockWatch.Elapsed;
                      calculateTotalTime();
  
                      CalculateFilteredTimeSpent();
                  }
              }
          }
      }
  }
  </code></pre>