title: C# Is it threadsafe to set dictionary object from one thread, get from other thread
body: <p>Suppose we have some <strong>strange</strong> class which contains </p>
  
  <ul>
  <li>public property <code>ReadOnlyDictionary&lt;string, string&gt; Map {get; private set;}</code> </li>
  <li>method <code>Update</code> which re-sets <code>Map</code> dictionary when called. </li>
  </ul>
  
  <p>Is it threadsafe to call method <code>Update</code> from one thread and get <code>Map</code> from other thread?</p>
  
  <pre><code>public class Example
  {
      public ReadOnlyDictionary&lt;string, string&gt; Map{ get; private set; }
  
      public void Update(IEnumerable&lt;KeyValuePair&lt;string, string&gt;&gt; items)
      {
          Map = items
              .ToLookup(x =&gt; x.Key)
              .ToDictionary(x =&gt; x.Key, x =&gt; x.First())
              .ToReadOnlyDictionary(); // helper method
      }
  }
  </code></pre>
  
  <p>Is it possible that there will be the moment when we call Map getter and it returns null or something in bad state, because of setter execution is not atomic? </p>