capture all events?

  • Thread starter Thread starter Erik Frey
  • Start date Start date
E

Erik Frey

Hi there,

Just curious as to whether there's a clever way to see the events a
control/object is firing off, perhaps written out to the debug console. It
would be really handy to know which events a control is firing when I
perform a certain action, and the order in which they are occurring.

Thanks,

Erik
 
Put a concole.writeline in an eventhandler for every event for the object in
question.
 
I was wondering if there was a -clever- way of doing it, dynamic for an
object you choose.

My initial thoughts were to use reflection to loop through all the event
signatures - I imagine you can do that. And adding a handler, with some
kind of dynamically created method? Maybe? I don't even know if such a
thing is possible.
 
Erik,
To dynamically create a method (class/Assembly) look at the
System.Reflection.Emit namespace. Word of advice, load the dynamic assembly
into a new AppDomain so you can unload it.

Alternatively you could use System.CodeDom to create a source module that
you later compile.

In either case you probably could have written a single module faster and
manually handle all the events! However! You would not have a cool utility
worth sharing, that would handle events out of any source. Of course if you
are going the cool utility route, be sure we can choose which events we want
handled! And post the utility on www.gotdotnet.com or someplace were the
rest of us can use it!

BTW: Dynamically handling events I think would be handy for utilities such
as www.nunit.org & www.csunit.org. Have an attribute that says this method
should raise this event. The tool would dynamically handle the event to be
certain it was raised. Similar to how they handles Exceptions.

Hope this helps
Jay
 
You could also look into bubble eventing. basically have everything point
to a sub that has the signiture (sp?) of (sender as object, e as
system.eventargs) and just keep adding handlers to it.

Then when you call the event handler (as an event is fired) you could do

console.writeline(e.gettype().tostring()) which will tell you what kind of
event argument handler your dealing with. and from there, you can pretty
much do what you want, since most event handlers have like signitures (and
are almost all derived from System.EventArgs...)

How is that for 'clever'
 
Back
Top