首页 > 代码库 > 【C#】监测文件改变类

【C#】监测文件改变类

using System.IO;

//
首先实例化一个对象FileSystemWatcher watcher = new FileSystemWatcher();//设置监听路径watcher.Path = Path.Combine(System.Environment.CurrentDirectory, @"eventTest\");//只监听这一个文件,当礼品目录修改完毕后对此文件进行修改,由此触发监听事件 watcher.Filter = "EventConfig.ini";watcher.NotifyFilter = NotifyFilters.LastWrite;//启用监听,如果不设置则不会触发事件watcher.EnableRaisingEvents = true;//设置监听触发事件watcher.Changed += new FileSystemEventHandler(watcher_Changed);

private void watcher_Changed(object sender, FileSystemEventArgs e){ WatchingEvent(EventConfigHelper.instance.WatchingNum);}

 

【C#】监测文件改变类