Breakpoints in event handlers not triggering

I've noticed that breakpoints in event handlers don't get triggered.

For example,

<Query Kind="Statements">
  <Namespace>LINQPad.Controls</Namespace>
</Query>

var button = new Button() { Text = "Click me!" };
button.Click += button_Click;
button.Dump();

void button_Click(object? sender, EventArgs e)
{
    "Clicked".Dump();
}

If you set a breakpoint on "Clicked".Dump(); and click the button, Clicked will still be dumped, but execution will not stop.

Is this something that can be fixed?

Comments

  • Add the following to the start of your script.

    Util.KeepRunning();

  • The key is that your "Main" method completed so LINQPad stops checking for progress. Since your script uses interactive elements, it's still technically running.

    Tell LINQPad it's still running as sgmoore pointed out, or if you have anything else useful to do, ensure that your main method doesn't fall off. Either firing off an event loop or having a long enough delay that your click will happen before it completes.