简体   繁体   English

查找在 FileSystemWatcher 中触发 Changed 事件时发生的更改

[英]Find what change occured when the Changed event is fired in a FileSystemWatcher

I am using a FileSystemWatcher to monitor changes to files.我正在使用FileSystemWatcher来监视对文件的更改。

MSDN documentation says that if Changed is passed for the ChangeType in the FileSystemEventArgs parameter, it indicated "The change of a file or folder. The types of changes include: changes to size, attributes, security settings, last write, and last access time." MSDN 文档说,如果为FileSystemEventArgs参数中的ChangeType传递Changed ,它表示“文件或文件夹的更改。更改的类型包括:对大小、属性、安全设置、上次写入和上次访问时间的更改。 "

Is there a way to find out which one of those changed?有没有办法找出其中哪一个发生了变化? For example, last access can alone change without change to size.例如,最后一次访问可以单独更改而不更改大小。 I want to find that out.我想知道这一点。 How can I do it?我该怎么做?

PS Of course if I record all the attributes that I care about every time Changed event is fired, and then compared them, I can find out what changed. PS当然,如果我每次触发Changed事件时记录下我关心的所有属性,然后比较它们,我就可以找出发生了什么变化。 But is there an easier way.. like being notified through some event or reading a property of some object?但是有没有更简单的方法......比如通过某个事件获得通知或读取某个 object 的属性? :D :D

You can use FileSystemWatcher.NotifyFilter to filter events based on what happened.您可以使用 FileSystemWatcher.NotifyFilter 根据发生的情况过滤事件。 MSDN MSDN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM