Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileSystemWatcher & InternalBufferSize 1

Status
Not open for further replies.

Tve

Programmer
May 22, 2000
166
FR
Hi,

I am using a FileSystemWatcher to monitor recursively file creation in a directory. Because there are really a lot of files, I wanted to increase the InternalBufferSize. I googled and found that if the buffer is not high enough on huge directories, it can actually miss some events.

So I simply do:

fsWatcher.InternalBufferSize = 32768;

This cause an argumentexception.

I put a try/catch around the statement, so no error pops-up but the stange thing is that when I interrogate the InternalBufferSize, it has actually been set to 32768.

What am I missing here?


AD AUGUSTA PER ANGUSTA

Thierry
 
according to this post the property should be set right before EnableRaisingEvents. not sure if that's the problem.

another thought would be to create mulitple FSW objects to monitor the subdirectories. this way memory consumption would be low.

Code:
public class myclass : idisposable
{
   private IList<filesystemwather> watchers;

   public myclass()
   {
      this.watchers = new List<filesystemwather>();
      this.addwatcher(@"C:\Documents and Settings\";);
   }

   private void addwatcher(string directory)
   {
      filesystemwatcher watcher = new new FileSystemWatcher(directory);
      watcher.includesubdirectories = false;
      watcher.created += new EventHandler(file_created);
      watcher.deleted += new EventHandler(file_deleted);
      //more propeties/events here...

      this.watchers.Add(wacher);

      foreach(string subdirectory in Directory.GetDirectories(directory))
      {
         this.addwatcher(subdirectory);
      }
   }

   private void file_created(object source, filesystemeventargs e)
   {
      //handle event
   }

   private void file_deleted(object source, filesystemeventargs e)
   {
      //handle event
   }

   public void dispose()
   {
      foreach(filesystemwatcher watcher in this.watchers)
      {
         watcher.dispose();
      }
      this.watchers.clear();
      this.watchers = null;
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Jason,

Nice code...

Thanks


AD AUGUSTA PER ANGUSTA

Thierry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top