25

Has anyone used the FileSystemWatcher in framework 4 and have you encountered any problems?

i am using it in a windows service and i cant afford for it to fail.

I have heard from a friend that it is not very reliable but I have been testing for a few hours now and i havent had any problems but i am still doubting using it.....

i would appreciate any advice on this matter, i dont want to deliver the app to the the client and then realise that this thing is going to crash....

Thanks


Thanks for the advice guys

i think for my purposes it should be ok. it will be checking a folder on the local drive of the server and all its checking for is if a file have been modified so i think it should be fine

Shog9
  • 156,901
  • 35
  • 231
  • 235
Yugz
  • 677
  • 1
  • 10
  • 23
  • 1
    A lot of people have unreasonable expectations of the FileSystemWatcher - such as believing "Created" means the file exists, has all of the data it was intended to contain, and no other program is currently accessing it. – Damien_The_Unbeliever Aug 25 '11 at 13:52
  • 1
    But there's also been cases in previous versions where FSW simply wouldn't pick up on obvious changes that it should have. I tried it once with the .net 2 version and found it useless for something as simple as watching for files being created (I wasn't even trying to access said files). – Tridus Aug 25 '11 at 13:54
  • 1
    The `FileSystemWatcher` is not what I'd call "relaible". If reliability is critical its best to use it as a convenience and also use polling to ensure that no files are missed. See [FileSystemWatcher vs polling to watch for file changes](http://stackoverflow.com/questions/239988/filesystemwatcher-vs-polling-to-watch-for-file-changes) – Justin Sep 04 '13 at 08:25

1 Answers1

44

FileSystemWatcher relies on underlying file system support, so any reliability issues with the file system will be visible as reliability issues with FileSystemWatcher. For example, if you are watching a network directory, then the network server's reliability will affect FileSystemWatcher's reliability. For example, the server may crash and be restarted. You will not be notified of changes that take place while network connectivity is lost. Or the server may simply have a bug that prevents FileSystemWatcher from working reliably.

Another point is that FileSystemWatcher only watches for changes to metadata. Not all file changes result in changes to metadata.

Walkman
  • 67
  • 1
  • 2
  • 8
Raymond Chen
  • 44,448
  • 11
  • 96
  • 135
  • 4
    https://petermeinl.wordpress.com/2015/05/18/tamed-filesystemwatcher/ *This post shares robust wrappers around the standard FileSystemWatcher (FSW) fixing problems commonly encountered when using it to monitor the file system in real-world applications.* – Kiquenet Jul 18 '18 at 20:45