private async Task RecData(CancellationToken token) { if (_running) { try { if (token.IsCancellationRequested) { return; } var result = await Operator.ReadLoop(AppSetting.Container.Resolve <IPhysicalCalculator>()); if (result.Any()) { _waveViewData.PushChannelWaveData(result.Last()); if (checkBoxSendData.Checked) { _toSendQueue.Enqueue(result.Last()); } _toSaveQueue.Enqueue(result.Last()); } } catch (BoundaryException bex) { if (token.CanBeCanceled) { _cancelSource.Cancel(); bex.Display += "\t数据接收已退出"; } ControlRenderInvoke.SafeInvoke(textBoxLog, () => AppendLog(bex.Display)); } catch (Exception ex) { var bex = new BoundaryException(ex); if (token.CanBeCanceled) { _cancelSource.Cancel(); bex.Display += "\t数据接收已退出"; } ControlRenderInvoke.SafeInvoke(textBoxLog, () => AppendLog(bex.Display)); } } }
private void _renderTimer_Tick(object aSender, EventArgs aE) { //Task.Run(() => { //RecData().ContinueWith(task => task.Wait()); PhysicalQuantity sendQ; if (_toSendQueue.TryDequeue(out sendQ)) { try { Task.Run(() => new Action(async() => { var send = new SendQuantityPackage(_sendLocalPort, SendRemoteIp, SendRemotePort, sendQ); await send.SendData(); })()); } catch (Exception ex) { var bex = new BoundaryException(ex); AppendLog(bex.Message); } } PhysicalQuantity quan; if (_toSaveQueue.TryDequeue(out quan)) { if (checkBoxEnableSaveLocal.Checked) { Task.Run(() => { //var dataArray = quan.ToDataString(); var dataArray = quan.ToTestDataString(); for (var i = 0; i < dataArray.Length; i++) { StressDataFile.SaveByChannel(dataArray[i], i + 1); } }); } ControlRenderInvoke.SafeInvoke(listViewQuantity, () => { try { if (listViewQuantity.Items.Count > 0) { for (var i = 0; i < GlobalSetting.Instance.SensorCount; i++) { var item = listViewQuantity.Items[i]; for (var j = 0; j < GlobalSetting.Instance.ChannelWay; j++) { var text = quan.ChannelValues[j].GratingValues[i].WaveLengthExtension.ToString(); item.SubItems[j + 1].Text = text; } } } else { for (var i = 0; i < GlobalSetting.Instance.SensorCount; i++) { var textArray = new string[GlobalSetting.Instance.ChannelWay + 1]; textArray[0] = ""; for (var j = 0; j < GlobalSetting.Instance.ChannelWay; j++) { textArray[j + 1] = quan.ChannelValues[j].GratingValues[i].WaveLengthExtension.ToString(); } listViewQuantity.Items.Add(new ListViewItem(textArray, -1)); } } } catch (Exception ex) { var bex = new BoundaryException(ex); AppendLog(bex.Display); } }); } } //); }