开发者

Managing Event's EventHandlers

开发者 https://www.devze.com 2023-02-18 15:59 出处:网络
I have a class that seems to be recursively adding an EventHandler to an event. I have looked at the code but th开发者_如何学Pythonere is no AddHandler on it and there\'s only one method with the Hand

I have a class that seems to be recursively adding an EventHandler to an event. I have looked at the code but th开发者_如何学Pythonere is no AddHandler on it and there's only one method with the Handles clause.

In the memory profiler it shows that the event handler is calling the event handler that is calling the event handler and so on for a rather large number of steps.

What could this be due to? What could be a good way to approach the situation in order to fix it?

P.S. I am new to this whole memory profiling thing so take it lightly on me ;).


It sounds more like you have an even whose handler is triggering the event again. The easiest way to tell this would be to set a breakpoint in the handler and see if it reenters the handler unexpectedly. If so, you can look at the stack trace and figure out what you're doing to trigger the event again.

If it's an event that might be affected by a pause (Paint, for example), you could write to the Console within the handler as well and print out Environment.StackTrace to get a snapshot without pausing execution.

0

精彩评论

暂无评论...
验证码 换一张
取 消