Do you specifically want to catch the red button? I'm not sure how to do that..
If you want to clean up after query run, both cancelled and failed:
// If you hit cancel within two seconds, a message box will be shown.
bool completed = false;
Util.Cleanup += (o, e) => { if (!completed) MessageBox.Show("Query cancelled."); };
Thread.Sleep(2000);
completed = true;
Comments
If you want to clean up after query run, both cancelled and failed: Source: http://forum.linqpad.net/discussion/906/kill-a-process-on-hitting-stop-button
Or: