Hello,
I could not follow the mechanism of the CLR how it updates the DateTime.Now property.
The following code should demonstrate my intention:
The result of the output is:Code:[STAThread] static void Main(string[] args) { for(int i=0;i<10;++i) { DateTime dt = DateTime.Now; Console.WriteLine("before the loop: ".PadRight(20,' ') + dt.Second + ":" + dt.Millisecond); for(int n=0; n<1000000; ++n); dt = DateTime.Now; Console.WriteLine("after the loop: ".PadRight(20,' ') + dt.Second + ":" + dt.Millisecond); } }
My questions are:Code:before the loop: 33:905 after the loop: 33:921 before the loop: 33:921 after the loop: 33:921 before the loop: 33:921 after the loop: 33:921 before the loop: 33:921 after the loop: 33:937 before the loop: 33:937 after the loop: 33:937 before the loop: 33:937 after the loop: 33:937 before the loop: 33:937 after the loop: 33:952 before the loop: 33:952 after the loop: 33:952 before the loop: 33:952 after the loop: 33:952 before the loop: 33:952 after the loop: 33:952
Why dosen't the milliseconds change on every step?
Are there other approaches?
Thanks
woodz




Reply With Quote