Can someone explain to me how custom event accessor works? I have read a couple of articles on google but still could not understand. Also, when to use it?
I have th
Without knowing exactly what part of the existing documentation and other references regarding custom event accessors it is specifically that you don't understand, it's impossible to know for sure what answer you're looking for.
A C# event
is simply an add
and a remove
method (similar to a property's get
and set
methods). The compiler provides a default implementation for these methods, but if you have custom behavior you want to implement yourself, you can write the methods yourself. In your example, which is not thread-safe by the way, the custom accessors are apparently there so that a newly subscribed delegate is invoked as soon as it's added.
If you need more details than that, please improve the question so that it's clear what it is specifically about custom event accessors that you are having trouble understanding. Be sure to explain exactly what you do understand and what documentation you've already referenced, so that we can avoid excessively long answers that waste time on aspects you already know about.