Event monitoring in a running application

G

Guest

Hi,

this seems like something so basic that there must be some way to do it...Is there a way for Visual Studio or some other tool to let me see Events as they are raised in an application?

For example, I've created a form with two fields. I would like to be able to see ALL the events for the application as I run/debug it. I want to know that clicking on field1 and then field2 produces: fld1.enter, fld1.leave, fld2.enter, etc.

I guess I should stipulate that I don't want to have to place breakpoints or debug writelines in the code. I don't want to have to anticipate which event handlers will be called. I want to see if events I didn't even expect are being raised.
 
S

Sunny

Hi,

lets say you have

public class MyForm : Form
{...}

Then you can use reflection over MyForm class, extract the list of all
events and subscribe a common method to everyone of them. And in this
method do whatever you want: Debug.Write, log in file, whatever.

All event handlers have the form MyHandler(object sender, EventArgs e),

so your handler can be:

void MyHandler(....)
{
Control control = sender as Control;
if (control != null)
{
//now here you can use control.Name to get who is the sender
//and use StackTrace to get the caller method, it should be
//something like OnXxxxx, so you will know what event was raised

}
}

And ... if you want all events for underlying controls, you have
complicate the things, and to iterate thru Controls collection of every
control, to get the events for every control and to subscribe them to
your handler as well.

But ... I doubt if you need such a thing. If you need to track down in
what sequence are raised the events to which you already has attached
handlers, you can use the Control.Events property to get all event
handlers already attached. And for every delegate in that list, you can
use Delegate.Combine to add your own tracking handler.

Sunny
 
K

Kevin Yu [MSFT]

Hi Ron,

I think there are many tools that can hook messages of a window, like
Spy++. Also there are some open source tools available. Control Inspector
is one of them, which deals with .NET managed applications. You can find
the tool with source code from the following link. HTH.

http://www.codeproject.com/csharp/controlinspector.asp

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
K

Kevin Yu [MSFT]

Hi Ron,

I'm not quite sure user defined events can be handled as we can only hook
messages from system. User defined events will not send messages.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top