Wednesday, July 6, 2011

Issues With File System Watcher And Large Amount of Files

File System Watcher notifies exactly at the moment when a file or directory is created, changed or deleted, without having to do polling on that directory.

But There is a problem when handling a large amount of files through the File System Watcher.
  • There is a fixed buffer allocated to each file system watcher (Default size of the buffer is 4 KB).
  • This Buffer is used to store the details such as file location for each file that raises an event.
  • When a large number of files raise an event then this buffer gets full.
  • So there is a possibility of missing some file information.
So the Solution for this problem is,
  • Do not write the proceeding logic in the handler instead the handler simply queues the file in a work queue.
  • Queue is processed by an entirely independent thread.
  • So the actual work done by the handler is just queuing and the control moves out of the handler thus releasing the buffer.
Code Example

  • In Main

  • Event Handler

  • Process




References :- http://csharp-codesamples.com/2009/02/file-system-watcher-and-large-file-volumes/

Unity configuration section with generic type

To use a Unity configuration section with generic types all you have to remember is the
` sign as the sign for a generic type in the configuration file.

  • Code


  • Configuration file



References :- http://stackoverflow.com/questions/3486837/unity-2-0-registering-generic-types-via-xml