tags:

views:

84

answers:

1

In the method monitorCallback() I write a the time to text file. after writing the file I check the FileInfo of file and print it.

I have got the following result:

time = 16/08/2009 14:01:46, mili = 307
time = 16/08/2009 14:01:51, mili = 291
time = 16/08/2009 14:01:56, mili = 291
time = 16/08/2009 14:02:01, mili = 291
time = 16/08/2009 14:02:06, mili = 291
time = 16/08/2009 14:02:11, mili = 291

I can't understand why the time is change but the Millisecond is stay fixed

 private Timer monitor;
 public Window1()
            {
                InitializeComponent();
                monitor = new Timer(monitorCallback, null, 0, 5000);
            }

    private void monitorCallback(object state)
            {
                string path = @"C:\Test.txt";
                Stream stream = File.OpenWrite(path);
                StreamWriter writer = new StreamWriter(stream);
                writer.WriteLine(DateTime.Now);
                writer.Close();

                FileInfo fileInfo = new FileInfo(path);
                Dispatcher.Invoke(DispatcherPriority.Normal,
                    new Action(delegate
                   {
                         Debug.WriteLine( "time = " + fileInfo.LastWriteTimeUtc + ", mili = " +
     fileInfo.LastWriteTimeUtc.Millisecond);


                   }));

                fileInfo = null;

            }
+2  A: 

You are calling this operation exactly every 5000 milliseconds. So if the operation takes less than 1 ms to complete, the millisecond part of the file's timestamp will not change, e.g:

  • time1 = 16/08/2009 14:01:51.291
  • time2 = 16/08/2009 14:01:56.291 (= time1 + 5000 ms)
  • etc.

Try changing the interval (e.g. to 5003 ms) to see that the millisecond part is updated.

M4N
the difference between the first timestamp and the second is 5000 milliseconds I should see this, The timestamp is changed but only this milliseconds property is not change
YairT