0

I'm using a system file watcher on a Windows Form app, it should detect *.mp4 files in a folder and sub directories and add the name to a grid. I also included another file system watcher to monitor *.txt files in another folder.

It works fine for a couple files, but then no longer works.

I have increased the buffer to max, changed the notification filters but still, after 3 or 4 catches it stops. My goal is to run the app all day long, is there a way to release the buffer programmatically? Or is there another property that could help?

obs: I use try so it don't act twice, as David suggested at https://stackoverflow.com/a/2780832/8684048

   try
      {
        fSW_Finalizados.EnableRaisingEvents = false;
        FoundFile(e.FullPath);
      }
      finally
      {
        fSW_Finalizados.EnableRaisingEvents = true;
      }

Thank you.

fdroid
  • 13
  • 1
  • 6
  • 1
    Could you show the code that is not working? – Steve May 27 '20 at 12:57
  • @Steve Added to the description. – fdroid May 27 '20 at 13:00
  • But how many files do you expect to handle? From what I can desume from docs every event requires 16 bytes plus the filename size, so if we assume to have very long filenames we could have a need for 255 bytes on average. This means space for 32 events in a standard 8KB buffer. If we expand to 64KB then the space is enough for 257 events before starting to loose track of new events. – Steve May 27 '20 at 13:05
  • Are your files stored on a network drive? I had that issue that I have explained in https://www.emoreau.com/Entries/Articles/2005/04/The-FileSystemWatcher-component.aspx – emoreau99 May 27 '20 at 13:05
  • @Steve About 4 files at once max, it's really not much. – fdroid May 27 '20 at 13:36
  • @emoreau99 Yes! They are. I'm following the advice to leave the filter property empty. I'm testing right now. – fdroid May 27 '20 at 13:37

1 Answers1

-1

DON'T USE FILESYSTEMWATCHER.

I experienced it a lots, and i recommand that you use a timer instead (that's what I do), that run every second or every 100 milisecond and watch if any new files come in your directories. As soon as you drop too many files in same times (hundreds) FileSystemWatcher stop to work, and only come back to life after you drop a new ones.

Use a timer, and a List of string to check when a file is added to your directories.

Bestter
  • 877
  • 1
  • 12
  • 29
  • as my first time with fswatcher I also consider as not reliable, if it still fails at the next tests I'll follow your Timer solution. Thank you. – fdroid May 27 '20 at 14:45