【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); }