diff --git a/Txgy.FilesWatcher/ViewModels/MainViewModel.cs b/Txgy.FilesWatcher/ViewModels/MainViewModel.cs index c5f96d6..68e4fbd 100644 --- a/Txgy.FilesWatcher/ViewModels/MainViewModel.cs +++ b/Txgy.FilesWatcher/ViewModels/MainViewModel.cs @@ -334,28 +334,33 @@ namespace Txgy.FilesWatcher.ViewModels DateTime lastWriteTime = File.GetLastWriteTime(e.FullPath); watcher.EnableRaisingEvents = false; Debug.WriteLine($"最后修改时间:{lastWriteTime}"); - string lastLine = File.ReadAllLines(e.FullPath).Last(); - System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => + string lastLine = File.ReadAllLines(e.FullPath).Last().Trim(); + var str= dataList.Where(f => f.Data == lastLine).FirstOrDefault(); + if (!string.IsNullOrWhiteSpace(lastLine) + && str==null) { - DataList.Add(new WatcherFileModel + System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => { - CreateTime = DateTime.Now.ToString(), - ChangeType = e.ChangeType, - Name = e.Name, - FullPath = e.FullPath, - Data = lastLine, - IsSend = false - }); - - CSDevicePublish cSDevicePublish = new CSDevicePublish() - { - type = CSMessage.publish, - message = lastLine, - serialNumber = DataList.Count, - }; - string jsonStr = JsonSerializer.Serialize(cSDevicePublish); - _websocketClient.SendMes(jsonStr); - })); + DataList.Add(new WatcherFileModel + { + CreateTime = DateTime.Now.ToString(), + ChangeType = e.ChangeType, + Name = e.Name, + FullPath = e.FullPath, + Data = lastLine, + IsSend = false + }); + + CSDevicePublish cSDevicePublish = new CSDevicePublish() + { + type = CSMessage.publish, + message = lastLine, + serialNumber = DataList.Count, + }; + string jsonStr = JsonSerializer.Serialize(cSDevicePublish); + _websocketClient.SendMes(jsonStr); + })); + } watcher.EnableRaisingEvents = true; }