title: Static member variable and thread safety
body: <p>I am working on an ASP.NET MVC application.</p>
  
  <p>I have a ViewModel class for which I am trying to maintain a count in order to generate div ids which are used in a view:</p>
  
  <pre><code>public class ViewModel {
  
      private static uint instanceCount;
      private readonly uint id;
  
      public ViewModel(){
          id = instanceCount++;
      }
  
      public uint DivId
      {
          get { return id; }
      }
  }
  </code></pre>
  
  <p>Am I correct in thinking incrementing and assigning the static member is not threadsafe and thus not safe in a web application?</p>
  
  <p>What is the best way to make this safe?</p>
  
  <p>Thanks.</p>