所以,这是我的C#程序大致的样子在我的情况下实现Filewatching的最佳方法?
Main()
// call to method that reads XML file and loads it into a list of structure
// call to method that works on the structure, manpulates data etc.
// call to method that starts filewatching
Filwatching_method()
// if any change is detected, calls method OnChange
OnChange()
// Action on change
如果OnChange
方法被调用,即已经检测到变化,我想重复一遍整个过程。我应该从OnChange
拨打Main()
,还是有另一种更好的方法?
Gotcha。我实际上并没有从主内部操作文件。我只读它,然后处理加载到内存上的内容并将其写入另一个文件。但是,当我从main()读取文件,会导致FileWatcher触发OnChange方法? – xbonez 2010-09-17 14:47:08
@xbonez:我老实不确定;如果观察者被设置为监视文件的最后访问属性,它*可能*触发事件。但是你可以很容易地自己测试一下。 – 2010-09-17 15:23:39