c# – FileSystemWatcher – ReadOnly属性的更改事件
作者:互联网
当受监视目录中的文件的ReadOnly属性发生更改时,看起来FileSystemMonitor未触发“已更改”事件(并且没有其他事件).
这是我的测试代码:
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.");
}
}
使用该代码,我收到了很多“已更改”的事件,例如如果修改时间戳已更改,但如果我正在更改任何标准属性(如ReadOnly或Hidden)则不会.
我错过了什么,还是我打了一个“功能”?
解决方法:
您需要设置NotifyFilter属性,因为这会确定要监视的更改类型.见FileSystemWatcher.NotifyFilter Property
例如
FolderMonitor.NotifyFilter = NotifyFilters.Attributes;
标签:c,net,filesystemwatcher,readonly-attribute 来源: https://codeday.me/bug/20190608/1198244.html