Checking if an event handler exists

c#, event-handling

Solution

This doesn't guarantee that there is only one handler fired.

Another location could, potentially, subscribe your handler to your event multiple times. In this case, you will only remove the first handler call.

By inspecting the invocation list of the event, you could guarantee this behavior, if you truly only want a single handler to be subscribed at a time.

Problem

Following on from this post - what are the disadvantages when using the `-=` then `+=` approach suggested when I only ever want one handler event to fire? ``` _value.PropertyChanged -= _handlerMethod; _value.PropertyChanged += _handlerMethod; ```

Original source

Related problems