title: DispatcherTimer eating up CPU over time causing WPF visual not rendering properly
body: <p>I have a WPF app that uses DispatcherTimer to update a clock tick.</p>
  
  <p>However, after my application has been running for approx 6 hours the clocks hands angles no longer change. I have verified that the DispatcherTimer is still firing with Debug and that the angle values are still updating, however the screen render does not reflect the change.</p>
  
  <p>I have also verified using WPFPerf tools Visual Profiler that the Unlabeled Time, Tick (Time Manager) and AnimatedRenderMessageHandler(Media Content) are all gradually growing until they are consuming nearly 80% of the CPU, however Memory is running stable.</p>
  
  <p>The  hHandRT.Angle is a reference to a RotateTransform  </p>
  
  <pre><code>hHandRT = new RotateTransform(_hAngle);
  </code></pre>
  
  <p>This code works perfectly for approx 5 hours of straight running but after that it delays and the angle change does not render to the screen. Any suggestions for how to troubleshoot this problem or any possible solutions you may know of. </p>
  
  <p>.NET 3.5, Windows Vista SP1 or Windows XP SP3 (both show the same behavior)</p>
  
  <p><strong>EDIT: Adding Clock Tick Function</strong></p>
  
  <pre><code>//In Constructor
  ...
  _dt = new DispatcherTimer();
  _dt.Interval = new TimeSpan(0, 0, 1);
  _dt.Tick += new EventHandler(Clock_Tick);
  ...
  
   private void Clock_Tick(object sender, EventArgs e)
          {
  
              DateTime startTime = DateTime.UtcNow;
              TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById(_timeZoneId);
              _now = TimeZoneInfo.ConvertTime(startTime, TimeZoneInfo.Utc, tst);
              int hoursInMinutes = _now.Hour * 60 + _now.Minute;
              int minutesInSeconds = _now.Minute * 60 + _now.Second;
              _hAngle = (double)hoursInMinutes * 360 / 720;
              _mAngle = (double)minutesInSeconds * 360 / 3600;
              _sAngle = (double)_now.Second * 360 / 60;
              // Use _sAngle to showcase more movement during Testing.
              //hHandRT.Angle = _sAngle;
              hHandRT.Angle = _hAngle;
              mHandRT.Angle = _mAngle;
              sHandRT.Angle = _sAngle;
  
              //DSEffect
              // Add Shadows to Hands creating a UNIFORM light
              //hands.Effect = textDropShadow;
          }
  </code></pre>
  
  <p>Along the lines of too much happening in the clock tick, I'm currently trying this adjustment to see if it helps. Too bad it takes 5 hours for the bug to manifest itself :(</p>
  
  <pre><code>  //DateTime startTime = DateTime.UtcNow;
    //TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById(_timeZoneId);
    //_now = TimeZoneInfo.ConvertTime(startTime, TimeZoneInfo.Utc, tst);
    _now = _now.AddSeconds(1);
  </code></pre>