Checking for an event handler

Following this post - what are the disadvantages of using the -=then approach +=, proposed when I only want a single handler event to fire?

_value.PropertyChanged -= _handlerMethod;
_value.PropertyChanged += _handlerMethod;
+3
source share
3 answers

This does not guarantee that there is only one handler.

Another place could potentially sign your handler for your event several times. In this case, you remove only the first call to the handler.

By checking the event call list, you can guarantee this behavior if you really want one handler to be signed at a time.

+4
source

, , . ; , .

+2

, - = , .

, , , , .

:  - , , ,  - , , _value.PropertyChanged - = _handlerMethod, .  - - , ,

+1
source

Source: https://habr.com/ru/post/1723684/


All Articles