[英]Why doesn't FileSystemWatcher detect changes from Visual Studio?
[英]FileSystemWatcher doesn't detect JPG rotation on Windows 10
我們的WPF應用程序中有一個FileSystemWatcher
,它監視目錄並實時顯示該目錄中的文件。 每次文件夾更改(創建,重命名,刪除或更改文件)時, FileSystemWatcher
刷新該實時視圖。
我們已經注意到,使用Windows資源管理器中的“ 旋轉”按鈕旋轉JPG文件時,不會觸發FileSystemWatcher
事件(它適用於PNG,BMP,TIFF和TIF文件):
雙擊文件並在照片應用中旋轉JPG會觸發事件,因此此處必須有所不同。
我只能在Windows 10上對其進行測試,但是我的同事確認它可以在以前的Windows版本中運行。
有沒有一種方法可以使用FileSystemWatcher
檢測JPG文件的旋轉,或者這是已知的錯誤?
可以使用以下代碼測試此問題:
public MainWindow()
{
InitializeComponent();
var watcher = new System.IO.FileSystemWatcher();
watcher.Path = Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures);
watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.Size;
watcher.Filter = "*.*";
watcher.IncludeSubdirectories = true;
watcher.EnableRaisingEvents = true;
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Changed += new FileSystemEventHandler(OnChanged);
}
private void OnChanged(object sender, FileSystemEventArgs e)
{
Debug.WriteLine("The file " + e.Name + " was " + e.ChangeType);
}
這很可能是因為JPEG旋轉通常由EXIF元數據標志控制。 因此,當您在資源管理器中旋轉jpeg時-不會執行實際的旋轉。 相反,它只是更改EXIF旋轉值(我記得可以是0、1、2、3等)。 在某些查看器中打開文件時,它會讀取旋轉標志並執行旋轉以進行顯示。 因為標志的大小固定(文件中的字節數固定),所以此操作不會更改文件的大小,而您只能跟蹤大小的更改。 要修復-將NotifyFilters.LastWrite
添加到FileSystemWatcher
過濾器。 還有其他操作不會更改文件的大小,因此無論如何這樣做都是有益的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.