Scrollpager doevents and margins of the main chart

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Scrollpager doevents and margins of the main chart

Post by acastro » Wed Feb 19, 2014 9:33 am

Please find attached this example
http://193.145.251.126/pnp/files/uOpbmT ... Scroll.zip

If you press button10 and then button1, the margin of the main chart is not correct. But if you comment the "DoEvents" instruction it runs sucessfully. Why?

Thanks

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Scrollpager doevents and margins of the main chart

Post by Christopher » Thu Feb 20, 2014 10:02 am

wakeup wrote:If you press button10 and then button1, the margin of the main chart is not correct. But if you comment the "DoEvents" instruction it runs sucessfully. Why?
I'm not sure, but according to this MSDN article:
Caution
Calling this method causes the current thread to be suspended while all waiting window messages are processed. If a message causes an event to be triggered, then other areas of your application code may execute. This can cause your application to exhibit unexpected behaviors that are difficult to debug. If you perform operations or computations that take a long time, it is often preferable to perform those operations on a new thread. For more information about asynchronous programming, see Asynchronous Programming Model (APM).
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: Scrollpager doevents and margins of the main chart

Post by acastro » Thu Feb 20, 2014 10:39 am

Christopher wrote:
wakeup wrote:If you press button10 and then button1, the margin of the main chart is not correct. But if you comment the "DoEvents" instruction it runs sucessfully. Why?
I'm not sure, but according to this MSDN article:
Caution
Calling this method causes the current thread to be suspended while all waiting window messages are processed. If a message causes an event to be triggered, then other areas of your application code may execute. This can cause your application to exhibit unexpected behaviors that are difficult to debug. If you perform operations or computations that take a long time, it is often preferable to perform those operations on a new thread. For more information about asynchronous programming, see Asynchronous Programming Model (APM).

As you can see in the example application it doesn't do anything special with doevents.

It is only a example application to reproduce the problem I have in the real application, it is because the user adds the series, and after do other things it fills it with data. This is only a demonstration it is a error in the teechart.

In fact, you can export this chart with the problem in the margin, and if you open it again the problem is solved...

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Scrollpager doevents and margins of the main chart

Post by Christopher » Thu Feb 20, 2014 11:04 am

wakeup wrote:It is only a example application to reproduce the problem I have in the real application, it is because the user adds the series, and after do other things it fills it with data. This is only a demonstration it is a error in the teechart.
No, it is not an error in TeeChart. The MSDN caution is quite clear. Calling Application.DoEvents() causes the current thread to be suspended, which for a Graphics application which depends on a running thread to do its calculations is bound to be problematic.

If you were to call Application.DoEvents() *after* TeeChart has finished all its calculations, that is, when it has finished drawing, then this is likely to be much less problematic. As an example, the following code works without any unexpected behaviour:

Code: Select all

        private void button10_Click(object sender, EventArgs e)
        {
          tChart1.AfterDraw += tChart1_AfterDraw;


          Steema.TeeChart.Styles.Line line = new Steema.TeeChart.Styles.Line(tChart1.Chart);
          line.LinePen.Width = 2;

          tChart1.Series.Add(line);

          tChart1.Series[0].XValues.DateTime = true;

          tChart1.Series[0].Add(new DateTime(2009, 7, 1, 0, 0, 0), 6525.4632);
          tChart1.Series[0].Add(new DateTime(2009, 7, 1, 0, 30, 0), 6325.000016);
        }

        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
          Application.DoEvents();
        }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: Scrollpager doevents and margins of the main chart

Post by acastro » Thu Feb 20, 2014 11:31 am

Ok, forget doevents, it was only an example, it is not the main issue.

Please change my example, add a new button Button11 like this code. And press button10, then button11, and then button1... You have the same problem...

Code: Select all

  private void button10_Click(object sender, EventArgs e)
        {

            Steema.TeeChart.Styles.Line line = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            line.LinePen.Width = 2;

            tChart1.Series.Add(line);

            tChart1.Series[0].XValues.DateTime = true;

        }

        private void button11_Click(object sender, EventArgs e)
        {
            tChart1.Series[0].Add(new DateTime(2009, 7, 1, 0, 0, 0), 6525.4632);
            tChart1.Series[0].Add(new DateTime(2009, 7, 1, 0, 30, 0), 6325.000016);
        }

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Scrollpager doevents and margins of the main chart

Post by Christopher » Thu Feb 20, 2014 11:48 am

wakeup wrote:Please change my example, add a new button Button11 like this code. And press button10, then button11, and then button1... You have the same problem...
Okay, I can see the problem now. It has nothing to do with the scrollpager tool. I have added it to our bugtracker with id=590.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: Scrollpager doevents and margins of the main chart

Post by acastro » Thu Feb 20, 2014 11:59 am

Ok. thanks

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Scrollpager doevents and margins of the main chart

Post by Christopher » Thu Feb 20, 2014 3:09 pm

wakeup wrote:Ok. thanks
FYI: this defect has now been fixed, and I've checked with your scrollpager code that all works as expected. Using Application.DoEvents also works as in your previous example of button10_Click :D
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: Scrollpager doevents and margins of the main chart

Post by acastro » Thu Feb 20, 2014 3:41 pm

Nice thanks a lot!

Post Reply