title: Thread safety with Dictionary<int,int> in .Net
body: <p>I have this function:  </p>
  
  <pre><code>static Dictionary&lt;int, int&gt; KeyValueDictionary = new Dictionary&lt;int, int&gt;();
  static void IncreaseValue(int keyId, int adjustment)
  {
      if (!KeyValueDictionary.ContainsKey(keyId))
      {
          KeyValueDictionary.Add(keyId, 0);
      }
      KeyValueDictionary[keyId] += adjustment;
  }
  </code></pre>
  
  <p>Which I would have thought would not be thread safe. However, so far in testing it I have not seen any exceptions when calling it from multiple threads at the same time.</p>
  
  <p>My questions: Is it thread safe or have I just been lucky so far? If it is thread safe then why?</p>