Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect newly created file, just edited file

Tags:

c#

.net

interrupt

I am trying to read a file on a timely basis the moment an edit or creation occurs. There is another piece of hardware that creates files to a folder which i wish to access (on a timely basis).

How does one go about detecting the creation a newly edited or created file using C# .net. I do not want to poll the folder on a periodic basis as the machine could potentially write several times in between the polling time interval. i.e. I want to avoid:

  • File 1 (created) 10:00:04AM
  • Poll file 1 ( no data lost ) 10:00:05AM
  • File 1 (overwritten with new data) 10:00:07AM
  • Poll File 1 ( no data lost ) 10:00:10AM
  • File 1 (overwritten with new data) 10:00:12AM
  • File 1 (overwritten with new data) 10:00:14AM
  • Poll File 1 ( 10:00:12AM data lost) 10:00:15AM
like image 984
Database Guy Avatar asked Dec 06 '22 22:12

Database Guy


1 Answers

It's simple, use FileSystemWatcher.

like image 78
Adi Avatar answered Dec 23 '22 10:12

Adi