I need to garuntee the uniqueness of an ID. Even if there's a 1 in 1 trillion chance of there being a dupe, I cannot use it.
But I don't really feel like going to the ends of the earth to find a solution either. I have spent some time looking into this, and everything I have found to date isn't able to garuntee me a unique ID.
So I thought I would use something very simple, like this:
public static string GenerateItemID()
{
string year = DateTime.Now.Year.ToString(),
month = DateTime.Now.Month.ToString(),
day = DateTime.Now.Day.ToString(),
hour = DateTime.Now.Hour.ToString(),
minute = DateTime.Now.Minute.ToString(),
second = DateTime.Now.Second.ToString(),
millisecond = DateTime.Now.Millisecond.ToString();
return year + month + day + hour + minute + second + millisecond;
}
My logic here is: each new UI that is generated can not possibly be the same as any of the previous ones. But then I wondered if it were possible for a PC to generate two or more of these ID's within the same millisecond? Naturally, I then looked in Intellisense for a Nanosecond property, but it doesn't exist.
How can I generate an ID that is garunteed to be unique?