TheNetStriker

I've programed a tool that uses the System.IO.FileSystemWatcher and I added a handler for the deleted event. The event usually works, but for some reason it stops to send the events sometimes. When I reset the events, then they are working again. My question is now, how can I find out when the event is not raised any more Do I have to write down and delete a File every x minutes, or is there a better way

Re: .NET Base Class Library System.IO.FileSystemWatcher loses events

Kim Hamilton - MSFT

Hi,

It's possible that you're not getting these events because of internal buffer overflow. Please see this note in the FileSystemWatcher docs:

http://msdn2.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx

The Windows operating system notifies your component of file changes in a buffer created by the FileSystemWatcher. 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 with the InternalBufferSize property is expensive, as it comes from non-paged memory that cannot be swapped out to disk, so keep the buffer as small yet large enough to not miss any file change events. To avoid a buffer overflow, use the NotifyFilter and IncludeSubdirectories properties so you can filter out unwanted change notifications.

I would start by adding a handler for the FileSystemWatcher Error event. This would help you determine if that's the cause (since this is most likely). Then you could either increase the buffer size or add filters (or both), using the guidance mentioned in the above paragraph.

Thanks,

Kim





Re: .NET Base Class Library System.IO.FileSystemWatcher loses events

TheNetStriker

Ok, thanks for your help, i will integrate a handler for these buffer events in my programm. But I also need an event when the network connection of a watchdir is disconnected.




Re: .NET Base Class Library System.IO.FileSystemWatcher loses events

theking2

Kim,

Just a small remark. The default value for IncludeSubdirectories is false. Wouldn't setting the IncludeSubdirectories to true just increase the possibility of a buffer overflow and or the size the buffer must be defined