Wednesday, September 05, 2007

Time Disappearing

In the following code that spawns a background task, resharper always whines about "_timer" not being used anywhere. So I removed variable and the background task never fired.

private static Timer _timer;
...
_timer = new Timer(_registrarCallback, textWriter, 0, registrarUpdateInMillisec);

This morning I learned why it needs that reference. Without the reference to the Timer object it can be garbage collected before it ever fires.

No comments: