Disabling FileSystemWatcher for specific updates?

Posted by chaiguy on Stack Overflow See other posts from Stack Overflow or by chaiguy
Published on 2010-05-09T02:43:33Z Indexed on 2010/05/09 2:48 UTC
Read the original article Hit count: 273

Filed under:
|
|

Does anyone have any ideas how I can reliably disable a FileSystemWatcher object when my application makes changes to the files in the directory, so that I am only watching for external changes to the directory?

I've tried setting EnableRaisingEvents to false immediately before performing a write and setting it back to true immediately after, but it seems this method is not reliable, and occasionally I still get the event firing.

The only other thing I can think of is to wait a small amount of time after performing the write to let the OS finish up the modification of the directory before re-enabling the FSW, but that seems hackish and I don't like it.


To add to the problem, the directory consists of potentially many files, the identities of which are beyond my knowledge and control, so I can't just wait for the event to fire for a specific file and then ignore it. There could be any number of FSW events firing after a single modification (because of the potentially many files getting updated).

© Stack Overflow or respective owner

Related posts about filesystemwatcher

Related posts about .NET