Skip to main content

Posts

Showing posts with the label NullReferenceException

Safest way to use EventHandlers in multi-threaded environment

Nowadays MVVM is one of the most common architectural structure and hope most of us working on WPF, Silverlight, Windows Phone or Windows Store apps might have come across this. When talking about MVVM, the first thing which strikes in mind is INotifyPropertyChanged interface. The usual and most common practice of implementing INotifyPropertyChanged is: public class ViewModelBase : INotifyPropertyChanged     {         public event PropertyChangedEventHandler PropertyChanged;         protected void RaisePropertyChanged(string prop)         {             if (PropertyChanged != null)             {                 PropertyChanged(this, new PropertyChangedEventArgs(prop));             }         }     } What do you think about the above code? In first ...