Search code examples
vb.netfilesystemwatcher

FileSystemWatcher Event Bubbling


I am using FileSystemWatcher to watch the incoming images (thru FTP) to the folder, where I am re-sizing the incoming images.

The problem is, I am re-sizing the images by overwriting the original images; because of this FileSystemWatcher is continuously creating changed events. I want to suppress the FileSystemWatcher events while i am working on re-sizing and saving the re-sized images. but not while files being copied using FTP, which may happen simultaneously. The incoming image count may reach up to 3000+ ...and I can not wait for more time to start processing.

Can anybody give me any solution to this.

Regards,

Amit Jog


Solution

  • Private thisFile as String = ""
    
    ' when resizing/etc:
    
    thisFile = Name_of_file
    

    Watcher event:

    Private Sub FileChanged(ByVal source As Object, ByVal e As  _
                    System.IO.FileSystemEventArgs)
    
        If e.FullPath.ToUpper = thisFile.ToUpper then exit sub
       ...
    
    End Sub
    

    You could also store all unprocessed images in a List(of String) and exempt them all as long as they are in the list (remove them when finished):

       If myList.Contains(e.FullPath.ToUpper) Then Exit Sub