[C#] 監控檔案變化
利用FileSystemWatcher這個類別來監控FileSystemWatcher fileWatcher = new FileSystemWatcher{
Path = watchingFolder,
NotifyFilter = NotifyFilters.Size | NotifyFilters.LastWrite,
Filter = "*.log",
EnableRaisingEvents = true,
};
_fileWatcher.Changed += FileWatcher_Changed;在以下事件處理器內加入檔案變更事件發生時想做的處理private void FileWatcher_Changed(object sender, FileSystemEventArgs e)
{
if (e.ChangeType == WatcherChangeTypes.Changed)
{
}
}要注意的是有些程式做儲存時,是先存入記憶體緩衝區,這種就不能及時偵測到變更
及時寫入磁碟區的動作就可以即時偵測到
頁:
[1]