title: How System.Timers.Timer behave in WPF application, after Hibernate, and Sleep?
body: <p>I'm using <strong>System.Timers.Timer</strong> in my WPF application. I want to understand how Timer does behave, after Computer is hibernated, and sleep. I'm getting some weird issues with my application, after computer is getting resumed from hibernate.</p>
  
  <p><strong>How should I handle timers, and how do they behave when computer is in hibernate/sleep mode?</strong></p>
  
  <p>I have a midnight timer which should work each midnight to reset the default values on UI.</p>
  
  <p>Here is the code that creates the timer:</p>
  
  <pre><code>private void ResetMidnightTimer() 
          { 
              // kill the old timer
              DisposeMidnightTimer();
  
              _midnightTimer = new Timer();
              // scheduling the timer to elapse 1 minute after midnight
              _midnightTimer.Interval = (DateTime.Today.AddDays(1).AddMinutes(1) - DateTime.Now).TotalMilliseconds;
              _midnightTimer.Elapsed += (_, __) =&gt; UpdateRecommendedCollectingTime();
              _midnightTimer.Enabled = true;
              _midnightTimer.Start();
          }
  </code></pre>
  
  <p>On UI page's contructor, I call the method which calls ResestMidnightTimer() and creates the timer de facto. After that the timer just waits for the night.</p>
  
  <p>When the night time (actually it is the 12:01 AM) comes, the timer works, resets the default values as expected and then disposes existing timer. Finally it creates a new midnight timer for next day.
  But if I try to hibernate the computer during that day, the midnight timer won't work and won't reset the default values.</p>
  
  <p><strong>Is that because while hibernating it just postpones the event handling by the same amount of time it was hibernated?</strong></p>