Dump() result does not appear in Result Pane when called from a Timer?

Can you explain why the following Dump() statement does not show the result in the Result Pane? (I am using Linqpad 5.0)

void Main()
{
Foo();
}

void Foo()
{
new Timer (_ => "Foo".Dump(), null, 3000, -1);
}

Comments

  • The query ends straightaway, try adding `Util.KeepRunning();` after `Foo();`
  • Your timer is getting garbage collected. You need to do this:
    void Main()
    {
       Foo();
    }
    
    static Timer _tmr;
    
    void Foo()
    {
       _tmr = new Timer (_ => "Foo".Dump(), null, 1000, -1);
    }
    You'll run into the same problem if you write an application in Visual Studio and use a System.Threading.Timer without maintaining a reference to it. Once the GC kicks in, your timer will get implicitly disposed.