DateTime.Now.Ticks repeating inside a loop

前端 未结 6 1105
小鲜肉
小鲜肉 2021-01-27 02:55

I am trying to generate a unique ID for the primary key of a table and I am using DateTime.Now.Ticks for it. That\'s a requirement for now we can\'t use Ident

6条回答
  •  有刺的猬
    2021-01-27 03:38

    To my knowledge, DateTime.Now.Ticks value is updated roughly every 15ms on most current computers, even though I've read that it can be updated every 1ms. Anyhow it is a value that needs to be updated by the OS and not directly read from the clock, so getting the same result in two different reads is expectable. I'd suggest that you use a different, as an auto increased value on the database or a GUID.

    This articles sheds some light on the matter: http://www.nullskull.com/articles/20021111.asp

提交回复
热议问题