ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Going Not responding when clicking on Home button after Zoom in or Zoom Out
Posted by Sahana Rao on Aug-20-2015 17:29
Attachments:
After zoom in and zoom out the graph, if I click on Home button while value of the chart is more(value is: 14826070.00000),Not responding message is getting displayed continuously after calling chartViewer.updateViewPort(true, false); May I know what is the reason for it and have suggestion for solving this problem? Below is the code snippet for your reference.


        private void OnHomeBtnCheckedChanged(object sender, EventArgs e)
        {
            if (Dispatcher.CheckAccess())
            {
                if (((System.Windows.Forms.RadioButton)sender).Checked)
                {
                    chartViewer.MouseUsage = WinChartMouseUsage.Default;

                    ChartControlDefinition chartDefinition = Definition as ChartControlDefinition;
                    double Samples = chartDefinition.MinutesToShow * 60;
                    chartViewer.ViewPortWidth = Samples / (_SampleSize - 1);

                    chartViewer.ViewPortLeft = 1 - chartViewer.ViewPortWidth;

                    int startIndex = (int)Math.Floor(chartViewer.getValueAtViewPort("x", chartViewer.ViewPortLeft));
                    int endIndex = (int)Math.Ceiling(chartViewer.getValueAtViewPort("x", chartViewer.ViewPortLeft + chartViewer.ViewPortWidth));
                    int noOfPoints = endIndex - startIndex + 1;

                    // Extract the part of the data array that are visible.
                    DateTime[] viewPortTimeStamps = (DateTime[])Chart.arraySlice(_TimeStamps, startIndex, noOfPoints);
                    double[] viewPortDataSeriesA = (double[])Chart.arraySlice(_DataSeriesA, startIndex, noOfPoints);

                    _StartTime = viewPortTimeStamps[0];
                    _EndTime = viewPortTimeStamps[0].AddMilliseconds(_DataTimer.Interval * Math.Max(1, viewPortTimeStamps.Length - 1));

                    _XYChart.xAxis().setDateScale2(_StartTime, _EndTime, _LabelList);

                    SetYAxisLimit(_YAxisLowerLimit, _YAxisUpperLimit);

                    //chartViewer.updateViewPort(true, false);
                }
            }
            else
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                {
                    OnHomeBtnCheckedChanged(sender, e);
                }));
            }
        }

//Method
  private void SetYAxisLimit(double lowerLimit, double upperLimit)
        {
            //Based on the Limit and current Device values Full range has to be fixed for the ChartViewer
            //And Current ViewPortTop and ViewPortHeight will be set to the Chartviewer based on Lower and Upper Limits

            if (double.IsNaN(_DataA) || double.IsInfinity(_DataA))
            {
                _DataA = 0.0;
            }

            if ((_DataA < 0 && lowerLimit < 0) || (_DataA < 0 && upperLimit > 0))
            {
                chartViewer.setFullRange("y", (lowerLimit + (_DataA - 500)), (upperLimit - (_DataA - 500)));
            }
            else
            {
                chartViewer.setFullRange("y", (lowerLimit - (_DataA + 500)), (upperLimit + (_DataA + 500)));
            }
            chartViewer.ViewPortTop = 1 - chartViewer.getViewPortAtValue("y", upperLimit);
            chartViewer.ViewPortHeight = 1 - chartViewer.getViewPortAtValue("y", lowerLimit) - chartViewer.ViewPortTop;

            if (Dispatcher.CheckAccess())
            {
                chartViewer.updateViewPort(true, false);
            }
            else
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                {
                    chartViewer.updateViewPort(true, false);
                }));
            }
        }
Image.png

  Re: Going Not responding when clicking on Home button after Zoom in or Zoom Out
Posted by Peter Kwan on Aug-21-2015 02:59
Hi Sahana,

In your code, you are using Dispatcher.CheckAccess. Is your code multi-threaded?

From my understanding, the Dispatcher.CheckAccess and Dispatcher.BeginInvoke only
applies to the object that owns the Dispatcher. For your case, it is the object that
contains the OnHomeBtnCheckedChanged method (Is it the containing Windows Form
object?). It should not apply to the chartViewer or your radio button. I do not quite
understand how it can be used to manage access to the chartViewer and the radio
button. Would you mind to clarify how the code works?

For testing, is it possible to run all your GUI code in the default GUI thread, so that you
do not need to use the Dispatcher and can remove all the dispatcher code? Usually,
people will run all GUI code in the default GUI thread, and time consuming non-GUI code
in "worker threads". So using Dispatcher is pure GUI code (such as inside the GUI event
handler) is not common. Removing the dispatcher can help to determine whether the
issue is due to the infinite loop caused by the Dispatcher or deadlock caused by multi-
threading.

It is also easy to create an infinite loop in GUI code. For example, if the code that
handles the view port changed event or the draw chart code modifies the user interface
(such as to reset the radio button), it may cause a loop. (When the button is changed, it
caused the view port changed event, and then it causes the button to change again,
causing a loop.) To check if there is a loop, you can try to insert debug statements
around updateViewPort to print information in the debugger window, like:

System.Diagnostics.Debug.WriteLine("Before updateViewPort");
chartViewer.updateViewPort(true, false);;
System.Diagnostics.Debug.WriteLine("After updateViewPort");

Regards
Peter Kwan

  Re: Going Not responding when clicking on Home button after Zoom in or Zoom Out
Posted by Sahana Rao on Aug-21-2015 17:05
Thank you..