C#: Using FileSystemWatcher to watch for changes to files

后端 未结 3 1562
醉梦人生
醉梦人生 2021-01-22 15:42

Ok, so I learnt from How to check if a open file has been updated that I should use a FileSystemWatcher to watch for changes to files. Then now, the question is if I must keep

3条回答
  •  我在风中等你
    2021-01-22 16:07

    It's enough if you create a watcher for each directory (and optionally, you can have the watcher to monitor a whole directory tree.) You can then use the events to compare the changed files with the list of files you are interested in.

    I would suggest you make some kind of "nanny" class for the watchers to ensure you doesn't dispose active watchers, or create duplicate. Just a tip :)

    Btw, yes, there's a limit, you can't create infinite watchers. In specific scenarios that can be a problem, but most likely, that's not the case for you

提交回复
热议问题