I have seen the following pattern used for implementing INotifyPropertyChanged
private void NotifyPropertyChanged(string propertyName)
{
PropertyChangedEvent
Eric Lippert explains this in details in this blog article: Events and races.
Basically, the idea is to avoid a race condition in case another thread unsubscribes the last handler for this event after you check PropertyChanged != null
, but before you actually invoke PropertyChanged
. If you make a local copy of the handler, this cannot happen (but you might end up calling a handler that's just been unsubscribed)