title: C# thread safety (in particular MVVM/WPF)
body: <p>I'm wondering what I need to do to make models thread safe in MVVM. Say I had the following class, which is instantiated as a singleton:</p>
  
  <pre><code>public class RunningTotal: INotifyPropertyChange
  {
     private int _total;
     public int Total
     {
        get { return _total; }
        set
        {
           _total = value;
           PropertyChanged("Total");
        }
     }
     ...etc...
  }
  </code></pre>
  
  <p>My view model exposes it via a property:</p>
  
  <pre><code>public RunningTotal RunningTotal { get; }
  </code></pre>
  
  <p>And my view has a textblock bound to it, i.e. <code>{Binding Path=RunningTotal.Total}</code>.</p>
  
  <p>My app has a background thread that periodically updates the value of Total. Assuming nothing else updates Total, what (if anything) should I do to make all this thread-safe?</p>
  
  <p>Now, what if I wanted to do something similar but using a property of type <code>Dictionary&lt;&gt;</code>, or <code>ObservableCollection&lt;&gt;</code>? Which members (add, remove, clear, indexer) are thread-safe? Should I use a ConcurrentDictionary instead?</p>