private static void OnFileChanged(Object source, FileSystemEventArgs e) { //采用临时禁用法解决触发两次事件的问题,只适合解决监控单个文件的处理 if (source != null) { var watcher = source as FileSystemWatcher; watcher.EnableRaisingEvents = false; Thread th = new Thread(new ThreadStart( delegate() { Thread.Sleep(1000); watcher.EnableRaisingEvents = true; } )); th.Start(); IsRestart = true; } LogerHelper.WriteOperateLog(string.Format("修改类型:{0},配置文件{0}被修改", e.ChangeType, e.FullPath)); LogerHelper.WriteOperateLog("是否重启服务:" + IsRestart); if (IsRestart) { //重启服务 ICommand command = new RestartCommand(); command.DealCommand(); IsRestart = false; } }
public static void ReStartService() { ICommand command = new RestartCommand(); command.DealCommand();//发送重启服务指令 }