示例#1
0
        public void ProcessChartUpdateLoop(int interval)
        {
            Task.Run(async delegate
            {
                try
                {
                    while (true)
                    {
                        LocalRepository localRepository = LocalRepository.GetInstance();

                        ProcessChartData data = new ProcessChartData();
                        for (int i = 0; i < localRepository.Tanks.Length; i++)
                        {
                            data.Level[i] = localRepository.Tanks[i].Level;
                        }
                        data.OperationMode = (int)localRepository.Pump.OperationMode;
                        data.PumpStatus    = (int)localRepository.Pump.Status;
                        localRepository.ProcessChart.Add(data);

                        await Task.Delay(interval);
                    }
                }
                catch (Exception exc)
                {
                    //TODO: Implementar framework de log
                }
            });
        }
示例#2
0
        public void UpdateChart(MsgChartData msg)
        {
            if (!btnRealtime.IsOn)
            {
                return;
            }

            MethodInvoker mth = (MethodInvoker) delegate()
            {
                try
                {
                    if (_IndexLastRenderedPoint > msg.Data.Count)
                    {
                        ClearChart();
                    }

                    while (_IndexLastRenderedPoint < msg.Data.Count)
                    {
                        ProcessChartData data = msg.Data[_IndexLastRenderedPoint];
                        if (_IndexLastRenderedPoint >= chtLevel.Series["Level1"].Points.Count)
                        {
                            chtLevel.Series["Level1"].Points.AddXY(data.SampleDate, data.Level[0]);
                            chtLevel.Series["Level2"].Points.AddXY(data.SampleDate, data.Level[1]);
                        }
                        ++_IndexLastRenderedPoint;
                    }
                }
                catch (Exception e)
                {
                    txtMsg.Text = e.Message;
                }
            };

            if (!this.IsHandleCreated)
            {
                mth.Invoke();
            }
            else
            {
                this.BeginInvoke(mth);
            }
        }