I have a program that uses the Now.ToFileTime() function in .NET to get a time-stamp for a file name. I’ve verified that this code is called on only 1 thread so I’m not worried about concurrency.
I have the following test code in my method:
Dim Time As String = Now.ToFileTime()
IO.File.AppendAllText("D:\test.txt", Time & " - " & System.Threading.Thread.CurrentThread.ManagedThreadId().ToString() & vbCrLf)
This ends up outputting the following to test.txt:
129899740120622239 - 4
129899740140465735 - 4
129899740140465735 - 4
129899740140465735 - 4
129899740140465735 - 4
129899740160465479 - 4
129899740160465479 - 4
129899740160621727 - 4
129899740160621727 - 4
So you can see that the time-stamp repeats itself 2 or more times. Occasionally I will get a unique one, but not very often. Shouldn’t I be getting unique times each time I call this method. The alls are at least a few mills apart. I don’t just invoke it sequentially (but even then I would expect to get different times).
Set a global variable and ensure it has changed before using it.