How to hook up cancel query event
Options
I want to do some clean up work after I hit the cancel query button. How do I call a function after this red button clicked?
Comments
-
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;
Source: http://forum.linqpad.net/discussion/906/kill-a-process-on-hitting-stop-button
Or:bool completed = false; try { Thread.Sleep(2000); completed = true; } finally { if (!completed) { MessageBox.Show("Query cancelled."); } }