I am trying to adapt Michael Dudley's sample code for my own implementation of a weak event manager:
Example implementation of weak events using .NET's WeakEventManager
I was wondering where would I put my user code for my own handler? I see this:
private EventHandler mHandler = (s, e) =>
{
CurrentManager.DeliverEvent(s, e);
return;
};
Would I replace the content of that expression with my own custom code?
Thank you,
Kevin
For most cases that handler should stay as it is. As a comment on that answer states, the handler declaration isn't even necessary. The following code for
StartListening
should be sufficient:((PropertyValue)source).Changed += DeliverEvent;
If you need to modify the values of
s
and/ore
before delivering the event you can add that code to the handler you posted. But no matter what,DeliverEvent
must be called. It loops through and callsReceiveWeakEvent
for all registered listeners and there's no way to get at the list of listeners unless you are storing them in your ownListenerList
. So, basically if you modify the event handler, it must still callDeliverEvent
or your weak event listeners will never be notified of the event.If you posted the code you're trying to find a place for, it might be a little easier to help you figure out what you are trying to accomplish and where it should go instead.