How to hook up cancel query event

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

  • edited February 25
    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.");
      }
    }
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!