Handling multiple Change Events in FileSystemWatcher

后端 未结 7 1626
别跟我提以往
别跟我提以往 2021-02-10 09:33

I have the following sub:

  Private Sub Watcher_Changed(ByVal sender As System.Object, ByVal e As FileSystemEventArgs)
        If Path.GetExtension(e.Name) = \".         


        
7条回答
  •  独厮守ぢ
    2021-02-10 09:59

    I had the same problem today while trying to automatically reload a configuration file on change. I ended up computing an MD5 hash of the file to figure out if the file had actually changed and only reloading if the hash was different. This was the only definitive way I could filter out duplicates.

    I briefly thought about using a timer mechanism to filter out change notifications but felt, like pete-m, but I felt it was too unclean a solution.

    I tried watching only for LastWrite time changes but that didn't work. I was still getting duplicate notifications.

提交回复
热议问题