c# - How to easilly see number of event subscriptions while debugging? -
while debugging, can textbox1.textchanged
see number of event subscriptions? if yes, how drill it? need know how many subscriptions there @ given time debugging because looks event triggered multiple times, suspect bug because textbox1.textchanged += handler
being mismanaged in application, there many subscribers.
here simplified version of think happening. if possible, want set breakpoint , count number of subscriptions "textbox1.textchanged":
private void textbox1_textchanged(object sender, eventargs e) { textbox1.textchanged += textbox1_textchanged; messagebox.show("asdf"); textbox1.textchanged -= textbox1_textchanged; textbox1.text = datetime.now.tostring(); textbox1.textchanged += textbox1_textchanged; }
is possible or more complicated?
you have use reflection invocation list of event delegate:
textbox1.textchanged += textbox1_textchanged; messagebox.show("asdf"); textbox1.textchanged -= textbox1_textchanged; textbox1.text = datetime.now.tostring(); textbox1.textchanged += textbox1_textchanged; var eventfield = textbox1.gettype().getfield("textchanged", bindingflags.getfield | bindingflags.nonpublic | bindingflags.instance); var subscribercount = ((eventhandler)eventfield.getvalue(textbox1)) .getinvocationlist().length;
Comments
Post a Comment