Rob Marsh
Rob Marsh

Reputation: 571

Changing InternalBufferSize on FileSystemWatcher for a network path

I've got a FileSystemWatcher in a windows service that I need to make the InternalBufferSize bigger on. I've set it to a multiple of 4096 (currently 20 * 4096). If I'm monitoring a local drive, I have no problems and everything works fine.

If I change the directory being monitored to a unc path, I get a 'The parameter is incorrect' error message, and no changes are picked up by the watcher.

Is there a way around this?

Upvotes: 0

Views: 1003

Answers (1)

Jeroen Mostert
Jeroen Mostert

Reputation: 28789

Per the documentation of the underlying unmanaged function ReadDirectoryChangesW:

ReadDirectoryChangesW fails with ERROR_INVALID_PARAMETER when the buffer length is greater than 64 KB and the application is monitoring a directory over the network. This is due to a packet size limitation with the underlying file sharing protocols.

Your buffer is 80 KB and exceeds this limit. See if the maximum (64 KB) will do for your purposes. If not, you'll have to work around it some other way -- increasing the buffer size is out, apparently.

Upvotes: 1

Related Questions