FileSystemWatcher Changed event is raised twice

前端 未结 30 3267
死守一世寂寞
死守一世寂寞 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条回答
  •  终归单人心
    2020-11-22 06:10

    Here is my solution which helped me to stop the event being raised twice:

    watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Size;
    

    Here I have set the NotifyFilter property with only Filename and size.
    watcher is my object of FileSystemWatcher. Hope this will help.

提交回复
热议问题