FileSystemWatcher Changed event is raised twice

前端 未结 30 3737
死守一世寂寞
死守一世寂寞 2020-11-22 06:01

I have an application where I am looking for a text file and if there are any changes made to the file I am using the OnChanged eventhandler to handle the event

30条回答
  •  Happy的楠姐
    2020-11-22 06:17

    I have created a Git repo with a class that extends FileSystemWatcher to trigger the events only when copy is done. It discards all the changed events exept the last and it raise it only when the file become available for read.

    Download FileSystemSafeWatcher and add it to your project.

    Then use it as a normal FileSystemWatcher and monitor when the events are triggered.

    var fsw = new FileSystemSafeWatcher(file);
    fsw.EnableRaisingEvents = true;
    // Add event handlers here
    fsw.Created += fsw_Created;
    

提交回复
热议问题