title: Check if File has been modified in time in C#
body: <p>I have an application that reads a file every 5 minutes. When the program starts, it reads the file and as soon as it completes it starts a timer. As soon as the 5 minutes passes, the timer stops and reads the file again.</p>
  
  <p>I would like to check if the file has been modified in that time period, if it is not, it does not read the file.</p>
  
  <p>Currently, I have the following code:</p>
  
  <pre><code>DateTime dtFile = File.GetLastWriteTime(file);
  DateTime now = DateTime.Now;
  
  long sub = (long)(now - dtFile).TotalMilliseconds;
  
  if(sub &lt;= timer1.Interval)
  {
      // the code goes here
  }
  </code></pre>
  
  <p>My problem is that my process has multiple files to read, then the process can take several minutes.</p>
  
  <p>Therefore, if the first file finishes execution at 10:00 am and the processing of all files ends at 10:05 am, the timer will start at 10:05 am.
  So the timer will stop at 10:10 am.</p>
  
  <p>If the first read file is modified at 10:02 am, it will not be read because the timer started running at the end of full processing at 10:05 am. So, the modified file at 10:02 am will be out of period.</p>