diff --git a/Correlator/Util/SerialPortManager.cs b/Correlator/Util/SerialPortManager.cs index 1a8d528..4fde315 100644 --- a/Correlator/Util/SerialPortManager.cs +++ b/Correlator/Util/SerialPortManager.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading; using System.Windows; +using System.Windows.Threading; using Correlator.Model; using Correlator.SensorHubTag; using GalaSoft.MvvmLight.Messaging; @@ -58,12 +59,23 @@ FlowStatus.RedSensorTagLists.Clear(); FlowStatus.BlueSensorTagLists.Clear(); - //开始计算 + //延迟5s开始计算 + _runningTimer.Start(); + } + }); + + _runningTimer.Tick += delegate + { + _runningSeconds++; + if (_runningSeconds >= 5) + { + _runningTimer.Stop(); Messenger.Default.Send(_dataModel, MessengerToken.HomePageDeviceData); + //重新定义dataModel,清空之前的缓存 _dataModel = new CorrelatorDataModel(); } - }); + }; } #endregion @@ -73,6 +85,15 @@ //左右传感器设备数据 private CorrelatorDataModel _dataModel = new CorrelatorDataModel(); + //计算时间 + private int _runningSeconds; + + //计时器 + private readonly DispatcherTimer _runningTimer = new DispatcherTimer + { + Interval = TimeSpan.FromSeconds(1) + }; + /// /// 数据监听委托解注册 /// diff --git a/Correlator/Util/SerialPortManager.cs b/Correlator/Util/SerialPortManager.cs index 1a8d528..4fde315 100644 --- a/Correlator/Util/SerialPortManager.cs +++ b/Correlator/Util/SerialPortManager.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading; using System.Windows; +using System.Windows.Threading; using Correlator.Model; using Correlator.SensorHubTag; using GalaSoft.MvvmLight.Messaging; @@ -58,12 +59,23 @@ FlowStatus.RedSensorTagLists.Clear(); FlowStatus.BlueSensorTagLists.Clear(); - //开始计算 + //延迟5s开始计算 + _runningTimer.Start(); + } + }); + + _runningTimer.Tick += delegate + { + _runningSeconds++; + if (_runningSeconds >= 5) + { + _runningTimer.Stop(); Messenger.Default.Send(_dataModel, MessengerToken.HomePageDeviceData); + //重新定义dataModel,清空之前的缓存 _dataModel = new CorrelatorDataModel(); } - }); + }; } #endregion @@ -73,6 +85,15 @@ //左右传感器设备数据 private CorrelatorDataModel _dataModel = new CorrelatorDataModel(); + //计算时间 + private int _runningSeconds; + + //计时器 + private readonly DispatcherTimer _runningTimer = new DispatcherTimer + { + Interval = TimeSpan.FromSeconds(1) + }; + /// /// 数据监听委托解注册 /// diff --git a/Correlator/ViewModel/HomePageProViewModel.cs b/Correlator/ViewModel/HomePageProViewModel.cs index 697a565..f6db7c0 100644 --- a/Correlator/ViewModel/HomePageProViewModel.cs +++ b/Correlator/ViewModel/HomePageProViewModel.cs @@ -523,15 +523,19 @@ //计算 try { + //异步保存定位数据 + new TaskFactory().StartNew(delegate + { + var fileName = _locateDataDir + "\\测试数据." + _locateTimes + "." + + DateTime.Now.ToString("HHmmss") + ".txt"; + StringUtil.SaveLocateData(it, fileName); + "HomePageViewModel".WriteLog("定位数据路径:" + fileName); + }); + + //异步计算数据 var task = new Task(() => CalculateData(it)); task.Start(); - //异步保存定位数据 - var fileName = _locateDataDir + "\\测试数据." + _locateTimes + "." - + DateTime.Now.ToString("HHmmss") + ".txt"; - StringUtil.SaveLocateData(it, fileName); - "HomePageViewModel".WriteLog("定位数据路径:" + fileName); - //同步保存截图,需要等待Task出结果并且渲染完成,才能保存截图 _snapShotPath = _locateDataDir + "\\快照." + _locateTimes + "." + DateTime.Now.ToString("HHmmss") + ".png";