我有兩個應用程序,CREATOR
(我不能修改)和OBSERVER
。 CREATOR操縱許多文件,我需要OBSERVER來知道這是什麼時候發生的。我用C#編寫了OBSERVER,並使用了FileSystemWatcher
。我將路徑設置爲我的路徑,將篩選器設置爲FILE
並添加所有必需的事件。但是,當CREATOR修改文件時,OBSERVER中不會引發任何事件。奇怪的是,當我手工修改文件時,OBSERVER 確實看到了更改。我認爲CREATOR可能不會釋放該文件,但是當我關閉CREATOR時,OBSERVER仍然看不到更改。問題fileSystemWatcher
任何想法我做錯了什麼?
額外的詳細信息: 當CREATOR修改文件,我可以手工刪除它,或者當我打開文件,我看到所有的更改都保存。
編輯
我FileSystemWatcher的對象設置:
fileSystemWatcherObs.EnableRaisingEvents = true;
fileSystemWatcherObs.Filter = "kbd.dbf";
fileSystemWatcherObs.IncludeSubdirectories = true;
fileSystemWatcherObs.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Attributes |
NotifyFilters.CreationTime | NotifyFilters.DirectoryName |NotifyFilters.LastAccess | NotifyFilters.Security |
NotifyFilters.Size;
fileSystemWatcherObs.Path = "D:\\FOLDER";
fileSystemWatcherObs.SynchronizingObject = this;
fileSystemWatcherObs.Changed += new System.IO.FileSystemEventHandler( this.fileSystemWatcherObs_Changed);
fileSystemWatcherObs.Created += new System.IO.FileSystemEventHandler(this.fileSystemWatcherObs_Created);
fileSystemWatcherObs.Deleted += new System.IO.FileSystemEventHandler(this.fileSystemWatcherObs_Deleted);
fileSystemWatcherObs.Renamed += new System.IO.RenamedEventHandler(this.fileSystemWatcherObs_Renamed);
,當然方法爲這個事件
請閱讀此:http://msmvps.com/blogs/jon_skeet/archive/2010/08/29/writing-the-perfect-question.aspx – Oded
因此,你有一個應用程序修改文件,而你用filesystemwatcher編寫和應用程序來檢查這些修改,但它沒有注意到你的「創建者」應用程序何時修改它們?請發佈您的「觀察員」應用程序的相關代碼。 – Aerik
是的,確切地說。我不知道我在做什麼錯誤 – nirmus