FileSystemWatcher not firing events

后端 未结 5 1551
感动是毒
感动是毒 2020-12-20 11:12

For some reason, my FileSystemWatcher is not firing any events whatsoever. I want to know any time a new file is created, deleted or renamed in my directory.

5条回答
  •  旧巷少年郎
    2020-12-20 11:28

    You seem to be creating the FileSystemWatcher as a local variable in the setup method. This will of course go out of scope at the end of the method and may well be getting tidied up at that point, thus removing the watches.

    Try creating the FSW at a point where it will be persisted (eg a program level variable) and see if that sorts you out.

提交回复
热议问题