title: DateTime.Now.Ticks repeating inside a loop
body: <p>I am trying to generate a unique ID for the primary key of a table and I am using <code>DateTime.Now.Ticks</code> for it. That's a requirement for now we can't use <code>Identity</code>. </p>
  
  <p>But sometimes, within a loop it generates same IDs on consecutive iterations. 
  My simplified Code would look like this</p>
  
  <pre><code>    While(IncomingData.Next())
      {
       IncomingData.ID = DateTime.Now.Ticks;
       // Other Operations
        .
        .
        .
       InsertInDatabase(IncomingData);
      }
  </code></pre>
  
  <p>Is it because my processor's speed for Instructions/sec is greater than the precision of at which <code>Ticks</code> is measured ? 
  I am using I5 2.9GHZ Processor. Though I have solved my problem by introducing a count variable and adding it to <code>ticks</code>. It Doesn't feel like a good approach. Anyway can someone break it down for me as how does a <code>tick</code> is calculated is it dependent on cpu cycle ? Thanks. </p>