-1

I have inherited application that, among many other things, has to watch if user writes/deletes text file into specific folder.

Currently, the application uses timer and polls after 5 seconds. I find this ineffective, and wish to improve this part of code.

My question is about existence of the .NET function that monitors changes in directory. Is there such function I can use to detect when a file is written/deleted in a specified folder?

Thank you.

AlwaysLearningNewStuff
  • 2,939
  • 3
  • 31
  • 84
  • 1
    Have a look at [`FileSystemWatcher`](http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher(v=vs.110).aspx) – Rhumborl Jan 15 '15 at 15:18

2 Answers2

2

Yes, you have the FileSystemWatcher class. It does exactly what you're looking for

Claudio Redi
  • 67,454
  • 15
  • 130
  • 155
0

Yes there is. I would suggest you take a look at the FileSystemWatcher class:

http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher%28v=vs.110%29.aspx

It's quite easy to set up, and it monitors for Win32 events, so is relatively inexpensive to use.

David G
  • 172
  • 2
  • 10