The FileSystemWatcher Buffer Size

Jeff again from the Windows SDK group.

.NET offers something called the FileSystemWatcher
that monitors a folder for changes and updated in files.

While the watcher itself is reliable, customers frequently
report that they are not seeing changes. The most common reason is that the
changes exceeded the buffer
size
. The default buffer size is only 8,192 bytes. The important thing to
remember is that file names allocated from this buffer size. If you are using long
file names, you can’t store many file changes in 8K. The maximum is 64K, and
should be allocated in 4K increments. Events received when the buffer is full
are lost.

From MSDN:

The system notifies the component of file
changes, and it stores those changes in a buffer the component creates and
passes to the APIs. Each event can use up to 16 bytes of memory, not including the file name. If there
are many changes in a short time, the buffer can overflow. This causes the
component to lose track of changes in the directory, and it will only provide
blanket notification. Increasing the size of the buffer can prevent missing
file system change events.

Save yourself the headache of missing events in the future,
increase the buffer size now to 64K.

/Jeff

Follow us on Twitter, www.twitter.com/WindowsSDK.