[英]FileSystemWatcher - Changed Event for ReadOnly Attribute
It looks like the FileSystemMonitor is not firing a 'Changed' event (and no other events) when the ReadOnly attribute of a file in the monitored directory is changed. 当受监视目录中的文件的ReadOnly属性发生更改时,看起来FileSystemMonitor未触发“已更改”事件(并且没有其他事件)。
This is my test code: 这是我的测试代码:
using System;
using System.IO;
namespace FSM
{
class Program
{
static FileSystemWatcher FolderMonitor;
static void Main(string[] args)
{
FolderMonitor = new FileSystemWatcher("C:\\MyImages");
FolderMonitor.IncludeSubdirectories = false;
FolderMonitor.Changed += FolderMonitor_Changed; ;
FolderMonitor.EnableRaisingEvents = true;
Console.WriteLine("Hit any key to terminate .....");
Console.ReadKey(true);
}
private static void FolderMonitor_Changed(object sender, FileSystemEventArgs e)
{
Console.WriteLine("**** \"" + e.Name + "\" changed.");
}
}
With that code, I am receiving a lot of 'Changed' events, eg if the modification timestamp has changed, but not if I am changing any standard attributes like ReadOnly or Hidden. 使用该代码,我收到了很多“已更改”事件,例如,如果修改时间戳已更改,但是如果我更改任何标准属性(如ReadOnly或Hidden)则不会。
Am I missing something, or have I hit a "feature"? 我错过了什么,还是我打了一个“功能”?
You need to set the NotifyFilter
property as this determines the type of changes that are watched for. 您需要设置NotifyFilter
属性,因为这会确定要监视的更改类型。 See FileSystemWatcher.NotifyFilter Property 请参见FileSystemWatcher.NotifyFilter属性
eg 例如
FolderMonitor.NotifyFilter = NotifyFilters.Attributes;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.