A reliable way to monitor changes to files in a directory using the .NET platform.

I am looking for a reliable way to find directory changes.

I tried using FileSystemWatcher, but it is pretty inaccurate when many small files are created, modified or deleted. In my tests, it skips about 1 or 2% of the files. This is quite a lot when you quickly add or change thousands of files.

I tried polling for changes at different intervals of 500 ms, 2000 ms, etc. In this case, I get too many hits. This may have something to do with resolving the timestamps of a FileInfo object.

So my question is; Is it possible using the .NET Framework to reliably get changes to a directory?

- Christian

+5
source share
2 answers

Have you tried to increase InternalBufferSize ? How much did you set it up?

From MSDN :


Note that FileSystemWatcher may skip the event when the buffer size is exceeded. To avoid missing events, follow these recommendations: Increase the buffer size by setting the InternalBufferSize property. Avoid viewing files with long file names, because a long file name contributes to filling the buffer. Consider renaming these files using shorter names.


Keep your event handling code as short as possible.

+7
source

, . , ( , ). , ( ), , .

(~ 6-9 - , , ), CallbackFilter . CallbackFilter API .NET, VCL ++.

+4

All Articles