Exemple #1
0
        private void TaskWork()
        {
            Thread.Sleep(2 * (_globalInfo.SamplesPerView / _globalInfo.SampleRate));
            while (true)
            {
                // 清空数据buffer并拷贝最新的数据
                this._dataBuf.Clear();
                bool getLock = false;
                try
                {
                    _globalInfo.DispBufLock.Enter(ref getLock);
                    this._dataBuf.AddRange(_globalInfo.DispBuf);
                }
                finally
                {
                    if (getLock)
                    {
                        _globalInfo.DispBufLock.Exit();
                    }
                }

                int samplesInChart = _globalInfo.SamplesInChart;
                if (samplesInChart <= 0)
                {
                    Thread.Sleep(Constants.FuncWaitTime);
                    continue;
                }
                if (_globalInfo.EnableRange)
                {
                    ShowDataRange();
                }

                int measureIndex = _parentForm.GetMeasureIndex();
                if (measureIndex >= 0)
                {
                    string[] result = _measure?.Execute(_dataBuf.GetRange(samplesInChart * measureIndex,
                                                                          samplesInChart).ToArray());
                    _parentForm.RefreshMeasureResult(result);
                }


                _function?.ExecuteAndShow();
                Thread.Sleep(Constants.FuncWaitTime);
            }
        }
Exemple #2
0
 private void FunctionExecutionTask()
 {
     Thread.Sleep(2 * (_globalInfo.SamplesPerView / _globalInfo.SampleRate));
     try
     {
         while (!this._cancellation.IsCancellationRequested)
         {
             Thread.Sleep(Constants.FuncWaitTime);
             // function变更时联动修改主界面的配置
             UpdateFunctionViewIfNecessary();
             // 清空数据buffer并拷贝最新的数据
             bool isUpdateSuccess = UpdateDataCache();
             if (!isUpdateSuccess)
             {
                 continue;
             }
             if (_globalInfo.EnableRange)
             {
                 ShowDataRange();
             }
             _function?.ExecuteAndShow();
         }
     }
     catch (ThreadAbortException)
     {
         // ignore
     }
     catch (Exception ex)
     {
         Task.Run(async() =>
         {
             await this._parentForm.StopTask();
             this._parentForm.ShowErrorMsg(ex.Message);
         });
     }
 }