I'm using FileSystemWatcher to monitor folder A. if a file is created or copied into that folder, it will be moved to folder B.
I created a file in folder A by right clicking, selecting "New", select "Text Document". The file is moved to folder B immediately. But if I use a program to create 1000 files into folder A then they are not moved to folder B. As it would seem FileSystemWatcher can't detect 1000 files were created by program.
Can anyone explain this for me?
Looks like a 1000 files will overrun the FileSystemWatcher's buffer. Great explanation here.
Link Excerpt:
Buffer Size and the Error Event
The FileSystemWatcher class works by capturing all of the relevant file and older changes and placing them into a buffer. This is then processed one change at a time until all of the notifications have been dealt with and the buffer is empty. By default, the internal buffer has a size of eight kilobytes (8192 bytes). Each event can take up to sixteen bytes of the buffer for its data, not including the file name. This means that when there are a lot of changes in a short period of time, the buffer can quickly become overloaded and notifications can be lost.
Handling the proper error event from FileSystemWatcher will allow you to code for this possibility. E.g. Examine and/or operate on the error event's folder with your own logic...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With