none
FileSystemWatcher not working when large amount of files are changed on short interval of time RRS feed

  • Question

  • We have used FileSystemWatcher to notify content changes on asp.net application that runs on webfarm.
    The FileSystemWatcher works fine when small no of files are changed due to it's internalbuffersize memory limitation.
    If we use maximum internalbuffersize memory it could only handle 4096 files changes.But we have a scenario where more than 20 thousands files could change on short interval of time.Is there any possible ways to use FileSystemWatcher to work on this scenario.
    Monday, December 2, 2013 7:45 AM

Answers

  • Hi Aasantosh,

    Unfortunately, MSDN has told us that you can set the buffer to 4 KB or larger, but it must not exceed 64 KB. If you try to set the InternalBufferSize property to less than 4096 bytes, your value is discarded and the InternalBufferSize property is set to 4096 bytes. For best performance, use a multiple of 4 KB on Intel-based computers. 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. However, increasing buffer size is expensive, because it comes from non-paged memory that cannot be swapped out to disk, so keep the buffer as small as possible. To avoid a buffer overflow, use the NotifyFilter and IncludeSubdirectories properties to filter out unwanted change notifications.

    Note that a FileSystemWatcher may miss an event when the buffer size is exceeded. To avoid missing events, follow these guidelines:

    • Increase the buffer size by setting the InternalBufferSize property.
    • Avoid watching files with long file names, because a long file name contributes to filling up the buffer. Consider renaming these files using shorter names.
    • Keep your event handling code as short as possible.

    http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher(v=vs.110).aspx

    http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.internalbuffersize(v=vs.110).aspx

    Hope useful to you.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, December 3, 2013 2:36 AM
    Moderator