And the Timer Sucks Because....

Following on from the last post, Ayende reminded me that I forgot to use reflector on the offending piece of code. Here is code taken straight from the System.Timers.Timer class that shows exactly why it is behaving the way it is (pay attention to the try block):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
private void MyTimerCallback(object state)
{
  if (state == this.cookie)
  {
    if (!this.autoReset)
    {
      this.enabled = false;

    }
    Timer.FILE_TIME file_time1 = new Timer.FILE_TIME();
    Timer.GetSystemTimeAsFileTime(ref file_time1);
    ElapsedEventArgs args1 = new ElapsedEventArgs(file_time1.ftTimeLow, file_time1.ftTimeHigh);
    try
    {
      ElapsedEventHandler handler1 = this.onIntervalElapsed;
      if (handler1 != null)
      {
        if ((this.SynchronizingObject != null) && this.SynchronizingObject.InvokeRequired)
        {
          this.SynchronizingObject.BeginInvoke(handler1, new object[]
          {
            this, args1
          });
        }
        else
        {
          handler1(this, args1);
        }
      }
    }
    catch
    {

      //if an exception occurs in the forest, does anyone handle it? 
    }

  }

}

And there we have it (ok, so I added in the comment in the catch block)!!

Comments