View Full Version : Button - detect function that is running and is done running?

You know in the *.Designer.cs file, you see a button with the event handler. In this case, "myButton.click += new System.EventHandler(this.myButton_Click);" run the event handler when a button is clicked.

I wonder how do I detect if this function "myButton_Click" is running so I can do the cursor to a WaitCursor and once the script is finish running with a return event would I change the cursor to a Default.

There got to be an easier way but I can't pin-point it. I do know I need to do a callback or delegate inside that "myButton_Click" function. So, can anyone provide a sample script that can detect when the function is running and is done.


Can't do it unless you can change the function.

In the method that handles the event, myButton_Click, why not wrap the code in a try/finally block? Save the cursor on entry, change it to a WaitCursor, then in the finally block revert to the initial saved cursor?

I did a little of that today and I realized that if I used this "return;" part of the script (see sample code below) then it wouldn't work becuase it exit the function.

You can do it, but it would require you to wire up eventhandlers manually in the Form's constructor rather than letting the Designer generate that code.

[code=C#]class Form1 : Form
public Form1()

//the Click events should still be null at this point.

//this is what you'd have to do for each Click event
//to call StartBusy(), then the appropriate eventhandler,
//then call EndBusy():