/// <summary> /// 开启 /// </summary> /// <param name="json"></param> public void Start(JsonConfigurationPath json) { var watcher = new FileSystemWatcher(); watcher.IncludeSubdirectories = false; watcher.Path = json.Path; watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.LastAccess | NotifyFilters.Size; watcher.Filter = json.Name; watcher.Changed += new FileSystemEventHandler(OnFileChanged); watcher.EnableRaisingEvents = true; }
/// <summary> /// 开启 /// </summary> /// <param name="json"></param> public void Start(JsonConfigurationPath json) { var watcher = new FileSystemWatcher { IncludeSubdirectories = false, Path = json.Path, NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.LastAccess | NotifyFilters.Size, Filter = json.Name }; watcher.Changed += OnFileChanged; watcher.EnableRaisingEvents = true; }
public void Start(JsonConfigurationPath conf) { var watcher = new FileSystemWatcher(); watcher.IncludeSubdirectories = false; watcher.Path = conf.Path; watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.LastAccess | NotifyFilters.Size; watcher.Filter = conf.Name; watcher.EnableRaisingEvents = true; Observable.FromEventPattern <FileSystemEventArgs>(watcher, "Changed") .Throttle(TimeSpan.FromSeconds(1)) .Subscribe(e => { if (!FileHelper.IsFileLocked(e.EventArgs.FullPath) && e.EventArgs.ChangeType == WatcherChangeTypes.Changed) { JsonConfigurationProvider.Set(e.EventArgs.Name, File.ReadAllText(e.EventArgs.FullPath)); } }, ex => { /* 处理异常 */ }, () => { /* 处理完成 */ } ); }