Hi,
I have three falstline series that are bound to a C# DataSet.
During real-time data acquisition I add data to the DataSet and
then call .CheckDataSource() for the series that I want updated.
After some number of acquired data points, perhaps 2000 or so
I get every time an exception:
"System.IndexOutOfRangeException in System.Windows.Forms.dll"
As soon as I replace the "CheckDataSource()" with the old-style
Add(double X, double Y) method I am in fat city and I can acquire
in real time data for hours (frequency about 5Hz).
This is example code from the Thread function that does the job:
//To update the dataset m_DS_RealTime_Run
myRow = m_DS_RealTime_Run.Tables["LoadedRunDataCol1"].NewRow();
myRow["Time"] = ttime;
myRow["UV"] = uv;
myRow["Conductivity"] = cond;
myRow["Volume"] = vol;
myRow["Temperature"] = "44";
myRow["PH"] = ph;
m_DS_RealTime_Run.Tables["LoadedRunDataCol1"].Rows.Add(myRow);
//To update the series (three of them)
//Commented since it cause a System.Windows.Forms.dll exception
//this.tChartAffinity.Series[0].CheckDataSource();
//this.tChartAffinity.Series[1].CheckDataSource();
//this.tChartAffinity.Series[2].CheckDataSource();
this.tChartAffinity.Series[0].Add(Convert.ToDouble(ttime),Convert.ToDouble(uv));
this.tChartAffinity.Series[1].Add(Convert.ToDouble(ttime),Convert.ToDouble(cond));
this.tChartAffinity.Series[2].Add(Convert.ToDouble(ttime),Convert.ToDouble(ph));
It would be nice if the CheckDatasource() would be able to handle
the acquisition.
Thanks.
Exception when using "CheckDatasSource()" in real
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi fano,
It works fine here using latest Debug Build available and this code:
Can you please test if it works for you? Please feel free to modify it so that we can reproduce the problem here. If this is not possible, could you please send us an example we can run "as-is" to reproduce the problem here? You can post your files at [url]news://www.steema.net/steema.public.attachments[/url] newsgroup.
BTW: You may be interested on this article on how to optimize real-time charting performance. It's a Delphi written article but you shouldn't have any problem porting it to any other environment.
It works fine here using latest Debug Build available and this code:
Code: Select all
private DataTable dt1, dt2, dt3;
private DataRow dr1, dr2, dr3;
private int i=0;
private void InitializeChart()
{
dt1 = new DataTable();
dt2 = new DataTable();
dt3 = new DataTable();
dt1.Columns.Add(new DataColumn("XValues", System.Type.GetType("System.Double")));
dt1.Columns.Add(new DataColumn("YValues", System.Type.GetType("System.Double")));
dt1.Columns.Add(new DataColumn("Labels", System.Type.GetType("System.String")));
dt2.Columns.Add(new DataColumn("XValues", System.Type.GetType("System.Double")));
dt2.Columns.Add(new DataColumn("YValues", System.Type.GetType("System.Double")));
dt2.Columns.Add(new DataColumn("Labels", System.Type.GetType("System.String")));
dt3.Columns.Add(new DataColumn("XValues", System.Type.GetType("System.Double")));
dt3.Columns.Add(new DataColumn("YValues", System.Type.GetType("System.Double")));
dt3.Columns.Add(new DataColumn("Labels", System.Type.GetType("System.String")));
}
private void Form1_Load(object sender, System.EventArgs e)
{
InitializeChart();
fastLine1.DataSource = dt1;
fastLine1.XValues.DataMember = dt1.Columns["XValues"].ToString();
fastLine1.YValues.DataMember = dt1.Columns["YValues"].ToString();
fastLine1.LabelMember = dt1.Columns["Labels"].ToString();
fastLine1.CheckDataSource();
fastLine2.DataSource = dt2;
fastLine2.XValues.DataMember = dt2.Columns["XValues"].ToString();
fastLine2.YValues.DataMember = dt2.Columns["YValues"].ToString();
fastLine2.LabelMember = dt2.Columns["Labels"].ToString();
fastLine2.CheckDataSource();
fastLine3.DataSource = dt3;
fastLine3.XValues.DataMember = dt3.Columns["XValues"].ToString();
fastLine3.YValues.DataMember = dt3.Columns["YValues"].ToString();
fastLine3.LabelMember = dt3.Columns["Labels"].ToString();
fastLine3.CheckDataSource();
}
private void timer1_Tick(object sender, System.EventArgs e)
{
Random rnd1 = new Random();
Random rnd2 = new Random();
Random rnd3 = new Random();
int j;
for (j=i;j<i+2000;++j)
{
dr1 = dt1.NewRow();
dr1["XValues"] = j;
dr1["YValues"] = rnd1.Next(100);
dt1.Rows.Add(dr1);
dr2 = dt2.NewRow();
dr2["XValues"] = j;
dr2["YValues"] = rnd2.Next(100);
dt2.Rows.Add(dr2);
dr3 = dt3.NewRow();
dr3["XValues"] = j;
dr3["YValues"] = rnd3.Next(100);
dt3.Rows.Add(dr3);
}
fastLine1.CheckDataSource();
fastLine2.CheckDataSource();
fastLine3.CheckDataSource();
i=j;
}
BTW: You may be interested on this article on how to optimize real-time charting performance. It's a Delphi written article but you shouldn't have any problem porting it to any other environment.
Best Regards,
Narcís Calvet / 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 |
Could Reproducable the exception with 'minor' change (thread
Hi,
Thanks for your example. I used it to reproduce the Exception. All I had to do was to move the code in the timer-function into a thread function.
I tried to download the project (as-is) to the link you gave but it always says: Could not send. Sender not specified. Check your news configuration.....
So I copy paste some stuff here. If you give me an Email address I can send it by Email as a zip file.
This basically your code example. I added a Thread and update the series there. The form has a checkbox that allows you to select to use 'CheckDataSource' ...this will cause the exception after some time of running. Be patient for a few minutes. If un-checked the thread function uses the old styel .Add(x,y) function and the problem is gone.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
//nf
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
namespace CheckListBox
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private Steema.TeeChart.TChart tChart1;
private System.ComponentModel.IContainer components;
private DataTable dt1, dt2, dt3;
private DataRow dr1, dr2, dr3;
private Steema.TeeChart.Styles.FastLine fastLine1;
private Steema.TeeChart.Styles.FastLine fastLine2;
private Steema.TeeChart.Styles.FastLine fastLine3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private int i=0;
private int xTime = 0;
private Thread t;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.Label label1;
private bool bUseCheckDataSource;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
t = new Thread(new ThreadStart(my_Thread));
bUseCheckDataSource = false;
}//Form1
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tChart1 = new Steema.TeeChart.TChart();
this.fastLine1 = new Steema.TeeChart.Styles.FastLine();
this.fastLine2 = new Steema.TeeChart.Styles.FastLine();
this.fastLine3 = new Steema.TeeChart.Styles.FastLine();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// tChart1
//
//
// tChart1.Aspect
//
this.tChart1.Aspect.View3D = false;
//
// tChart1.Header
//
this.tChart1.Header.Lines = new string[] {
"TeeChart"};
//
// tChart1.Legend
//
//
// tChart1.Legend.Title
//
//
// tChart1.Legend.Title.Font
//
this.tChart1.Legend.Title.Font.Bold = true;
//
// tChart1.Legend.Title.Pen
//
this.tChart1.Legend.Title.Pen.Visible = false;
this.tChart1.Location = new System.Drawing.Point(40, 16);
this.tChart1.Name = "tChart1";
this.tChart1.Series.Add(this.fastLine1);
this.tChart1.Series.Add(this.fastLine2);
this.tChart1.Series.Add(this.fastLine3);
this.tChart1.Size = new System.Drawing.Size(712, 320);
this.tChart1.TabIndex = 0;
//
// fastLine1
//
//
// fastLine1.LinePen
//
this.fastLine1.LinePen.Color = System.Drawing.Color.Red;
this.fastLine1.Title = "fastLine1";
//
// fastLine1.XValues
//
this.fastLine1.XValues.DataMember = "X";
this.fastLine1.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending;
//
// fastLine1.YValues
//
this.fastLine1.YValues.DataMember = "Y";
//
// fastLine2
//
//
// fastLine2.LinePen
//
this.fastLine2.LinePen.Color = System.Drawing.Color.Green;
this.fastLine2.Title = "fastLine2";
//
// fastLine2.XValues
//
this.fastLine2.XValues.DataMember = "X";
this.fastLine2.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending;
//
// fastLine2.YValues
//
this.fastLine2.YValues.DataMember = "Y";
//
// fastLine3
//
//
// fastLine3.LinePen
//
this.fastLine3.LinePen.Color = System.Drawing.Color.Yellow;
this.fastLine3.Title = "fastLine3";
//
// fastLine3.XValues
//
this.fastLine3.XValues.DataMember = "X";
this.fastLine3.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending;
//
// fastLine3.YValues
//
this.fastLine3.YValues.DataMember = "Y";
//
// button1
//
this.button1.Location = new System.Drawing.Point(496, 368);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 40);
this.button1.TabIndex = 1;
this.button1.Text = "Start Thread";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(608, 368);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 40);
this.button2.TabIndex = 2;
this.button2.Text = "Stop Thread";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// checkBox1
//
this.checkBox1.Location = new System.Drawing.Point(48, 368);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(288, 16);
this.checkBox1.TabIndex = 3;
this.checkBox1.Text = "Use \'CheckDataSource\' ...otherwise plain .Add(x,y)";
//
// label1
//
this.label1.Location = new System.Drawing.Point(48, 400);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(392, 40);
this.label1.TabIndex = 4;
this.label1.Text = "To reproduce the \'System.IndexOutofRangeException\' in System.Windows.Forms.dll ch" +
"eck the checkbox., then click \'Start\' and wait some time ... be patient.";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(824, 453);
this.Controls.Add(this.label1);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.tChart1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void InitializeChart()
{
dt1 = new DataTable();
dt2 = new DataTable();
dt3 = new DataTable();
dt1.Columns.Add(new DataColumn("XValues", System.Type.GetType("System.Double")));
dt1.Columns.Add(new DataColumn("YValues", System.Type.GetType("System.Double")));
dt1.Columns.Add(new DataColumn("Labels", System.Type.GetType("System.String")));
dt2.Columns.Add(new DataColumn("XValues", System.Type.GetType("System.Double")));
dt2.Columns.Add(new DataColumn("YValues", System.Type.GetType("System.Double")));
dt2.Columns.Add(new DataColumn("Labels", System.Type.GetType("System.String")));
dt3.Columns.Add(new DataColumn("XValues", System.Type.GetType("System.Double")));
dt3.Columns.Add(new DataColumn("YValues", System.Type.GetType("System.Double")));
dt3.Columns.Add(new DataColumn("Labels", System.Type.GetType("System.String")));
}
private void Form1_Load(object sender, System.EventArgs e)
{
InitializeChart();
fastLine1.DataSource = dt1;
fastLine1.XValues.DataMember = dt1.Columns["XValues"].ToString();
fastLine1.YValues.DataMember = dt1.Columns["YValues"].ToString();
fastLine1.LabelMember = dt1.Columns["Labels"].ToString();
fastLine1.CheckDataSource();
fastLine2.DataSource = dt2;
fastLine2.XValues.DataMember = dt2.Columns["XValues"].ToString();
fastLine2.YValues.DataMember = dt2.Columns["YValues"].ToString();
fastLine2.LabelMember = dt2.Columns["Labels"].ToString();
fastLine2.CheckDataSource();
fastLine3.DataSource = dt3;
fastLine3.XValues.DataMember = dt3.Columns["XValues"].ToString();
fastLine3.YValues.DataMember = dt3.Columns["YValues"].ToString();
fastLine3.LabelMember = dt3.Columns["Labels"].ToString();
fastLine3.CheckDataSource();
}
private void button1_Click(object sender, System.EventArgs e)
{
StartStopReadHID();
}
private void button2_Click(object sender, System.EventArgs e)
{
StartStopReadHID();
}
/// <summary>
/// Used to start/stop the thread function
/// </summary>
private void StartStopReadHID()
{
if(t.ThreadState.ToString() == "Unstarted")
{
// Start the thread
// Upon start of the thread, my_Thread() executes
t.Start();
t.Join(1000);
Thread.Sleep(0);
}
else
{
if(t.ThreadState.ToString() == "Running")
{ //Stop/Abort the thread
Thread.Sleep(1);
t.Abort();
t.Join();
}
}
}//StartStopReadHID
/// <summary>
/// This happens when the Thread is started.
/// </summary>
private void my_Thread()
{
while(true)
{
Random rnd1 = new Random();
Random rnd2 = new Random();
Random rnd3 = new Random();
dr1 = dt1.NewRow();
dr1["XValues"] = xTime;
dr1["YValues"] = rnd1.Next(100);
dt1.Rows.Add(dr1);
dr2 = dt2.NewRow();
dr2["XValues"] = xTime;
dr2["YValues"] = rnd2.Next(200);
dt2.Rows.Add(dr2);
dr3 = dt3.NewRow();
dr3["XValues"] = xTime;
dr3["YValues"] = rnd3.Next(50);
dt3.Rows.Add(dr3);
if(checkBox1.Checked)
{
fastLine1.CheckDataSource();
fastLine2.CheckDataSource();
fastLine3.CheckDataSource();
}
else
{
fastLine1.Add(xTime,rnd1.Next(100));
fastLine2.Add(xTime,rnd2.Next(200));
fastLine3.Add(xTime,rnd3.Next(50));
}
xTime++;
}//while
}
}
}
Thanks for your example. I used it to reproduce the Exception. All I had to do was to move the code in the timer-function into a thread function.
I tried to download the project (as-is) to the link you gave but it always says: Could not send. Sender not specified. Check your news configuration.....
So I copy paste some stuff here. If you give me an Email address I can send it by Email as a zip file.
This basically your code example. I added a Thread and update the series there. The form has a checkbox that allows you to select to use 'CheckDataSource' ...this will cause the exception after some time of running. Be patient for a few minutes. If un-checked the thread function uses the old styel .Add(x,y) function and the problem is gone.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
//nf
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
namespace CheckListBox
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private Steema.TeeChart.TChart tChart1;
private System.ComponentModel.IContainer components;
private DataTable dt1, dt2, dt3;
private DataRow dr1, dr2, dr3;
private Steema.TeeChart.Styles.FastLine fastLine1;
private Steema.TeeChart.Styles.FastLine fastLine2;
private Steema.TeeChart.Styles.FastLine fastLine3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private int i=0;
private int xTime = 0;
private Thread t;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.Label label1;
private bool bUseCheckDataSource;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
t = new Thread(new ThreadStart(my_Thread));
bUseCheckDataSource = false;
}//Form1
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tChart1 = new Steema.TeeChart.TChart();
this.fastLine1 = new Steema.TeeChart.Styles.FastLine();
this.fastLine2 = new Steema.TeeChart.Styles.FastLine();
this.fastLine3 = new Steema.TeeChart.Styles.FastLine();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// tChart1
//
//
// tChart1.Aspect
//
this.tChart1.Aspect.View3D = false;
//
// tChart1.Header
//
this.tChart1.Header.Lines = new string[] {
"TeeChart"};
//
// tChart1.Legend
//
//
// tChart1.Legend.Title
//
//
// tChart1.Legend.Title.Font
//
this.tChart1.Legend.Title.Font.Bold = true;
//
// tChart1.Legend.Title.Pen
//
this.tChart1.Legend.Title.Pen.Visible = false;
this.tChart1.Location = new System.Drawing.Point(40, 16);
this.tChart1.Name = "tChart1";
this.tChart1.Series.Add(this.fastLine1);
this.tChart1.Series.Add(this.fastLine2);
this.tChart1.Series.Add(this.fastLine3);
this.tChart1.Size = new System.Drawing.Size(712, 320);
this.tChart1.TabIndex = 0;
//
// fastLine1
//
//
// fastLine1.LinePen
//
this.fastLine1.LinePen.Color = System.Drawing.Color.Red;
this.fastLine1.Title = "fastLine1";
//
// fastLine1.XValues
//
this.fastLine1.XValues.DataMember = "X";
this.fastLine1.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending;
//
// fastLine1.YValues
//
this.fastLine1.YValues.DataMember = "Y";
//
// fastLine2
//
//
// fastLine2.LinePen
//
this.fastLine2.LinePen.Color = System.Drawing.Color.Green;
this.fastLine2.Title = "fastLine2";
//
// fastLine2.XValues
//
this.fastLine2.XValues.DataMember = "X";
this.fastLine2.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending;
//
// fastLine2.YValues
//
this.fastLine2.YValues.DataMember = "Y";
//
// fastLine3
//
//
// fastLine3.LinePen
//
this.fastLine3.LinePen.Color = System.Drawing.Color.Yellow;
this.fastLine3.Title = "fastLine3";
//
// fastLine3.XValues
//
this.fastLine3.XValues.DataMember = "X";
this.fastLine3.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending;
//
// fastLine3.YValues
//
this.fastLine3.YValues.DataMember = "Y";
//
// button1
//
this.button1.Location = new System.Drawing.Point(496, 368);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 40);
this.button1.TabIndex = 1;
this.button1.Text = "Start Thread";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(608, 368);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 40);
this.button2.TabIndex = 2;
this.button2.Text = "Stop Thread";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// checkBox1
//
this.checkBox1.Location = new System.Drawing.Point(48, 368);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(288, 16);
this.checkBox1.TabIndex = 3;
this.checkBox1.Text = "Use \'CheckDataSource\' ...otherwise plain .Add(x,y)";
//
// label1
//
this.label1.Location = new System.Drawing.Point(48, 400);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(392, 40);
this.label1.TabIndex = 4;
this.label1.Text = "To reproduce the \'System.IndexOutofRangeException\' in System.Windows.Forms.dll ch" +
"eck the checkbox., then click \'Start\' and wait some time ... be patient.";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(824, 453);
this.Controls.Add(this.label1);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.tChart1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void InitializeChart()
{
dt1 = new DataTable();
dt2 = new DataTable();
dt3 = new DataTable();
dt1.Columns.Add(new DataColumn("XValues", System.Type.GetType("System.Double")));
dt1.Columns.Add(new DataColumn("YValues", System.Type.GetType("System.Double")));
dt1.Columns.Add(new DataColumn("Labels", System.Type.GetType("System.String")));
dt2.Columns.Add(new DataColumn("XValues", System.Type.GetType("System.Double")));
dt2.Columns.Add(new DataColumn("YValues", System.Type.GetType("System.Double")));
dt2.Columns.Add(new DataColumn("Labels", System.Type.GetType("System.String")));
dt3.Columns.Add(new DataColumn("XValues", System.Type.GetType("System.Double")));
dt3.Columns.Add(new DataColumn("YValues", System.Type.GetType("System.Double")));
dt3.Columns.Add(new DataColumn("Labels", System.Type.GetType("System.String")));
}
private void Form1_Load(object sender, System.EventArgs e)
{
InitializeChart();
fastLine1.DataSource = dt1;
fastLine1.XValues.DataMember = dt1.Columns["XValues"].ToString();
fastLine1.YValues.DataMember = dt1.Columns["YValues"].ToString();
fastLine1.LabelMember = dt1.Columns["Labels"].ToString();
fastLine1.CheckDataSource();
fastLine2.DataSource = dt2;
fastLine2.XValues.DataMember = dt2.Columns["XValues"].ToString();
fastLine2.YValues.DataMember = dt2.Columns["YValues"].ToString();
fastLine2.LabelMember = dt2.Columns["Labels"].ToString();
fastLine2.CheckDataSource();
fastLine3.DataSource = dt3;
fastLine3.XValues.DataMember = dt3.Columns["XValues"].ToString();
fastLine3.YValues.DataMember = dt3.Columns["YValues"].ToString();
fastLine3.LabelMember = dt3.Columns["Labels"].ToString();
fastLine3.CheckDataSource();
}
private void button1_Click(object sender, System.EventArgs e)
{
StartStopReadHID();
}
private void button2_Click(object sender, System.EventArgs e)
{
StartStopReadHID();
}
/// <summary>
/// Used to start/stop the thread function
/// </summary>
private void StartStopReadHID()
{
if(t.ThreadState.ToString() == "Unstarted")
{
// Start the thread
// Upon start of the thread, my_Thread() executes
t.Start();
t.Join(1000);
Thread.Sleep(0);
}
else
{
if(t.ThreadState.ToString() == "Running")
{ //Stop/Abort the thread
Thread.Sleep(1);
t.Abort();
t.Join();
}
}
}//StartStopReadHID
/// <summary>
/// This happens when the Thread is started.
/// </summary>
private void my_Thread()
{
while(true)
{
Random rnd1 = new Random();
Random rnd2 = new Random();
Random rnd3 = new Random();
dr1 = dt1.NewRow();
dr1["XValues"] = xTime;
dr1["YValues"] = rnd1.Next(100);
dt1.Rows.Add(dr1);
dr2 = dt2.NewRow();
dr2["XValues"] = xTime;
dr2["YValues"] = rnd2.Next(200);
dt2.Rows.Add(dr2);
dr3 = dt3.NewRow();
dr3["XValues"] = xTime;
dr3["YValues"] = rnd3.Next(50);
dt3.Rows.Add(dr3);
if(checkBox1.Checked)
{
fastLine1.CheckDataSource();
fastLine2.CheckDataSource();
fastLine3.CheckDataSource();
}
else
{
fastLine1.Add(xTime,rnd1.Next(100));
fastLine2.Add(xTime,rnd2.Next(200));
fastLine3.Add(xTime,rnd3.Next(50));
}
xTime++;
}//while
}
}
}
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi fano,
Thanks to your code we have been able to reproduce your problem and we found a solution which is applying "asynchronous painting" tecnique setting Autorepaint=false and then forcing the chart being painted by calling to Refresh() method, as you can see in the code below:
Thanks to your code we have been able to reproduce your problem and we found a solution which is applying "asynchronous painting" tecnique setting Autorepaint=false and then forcing the chart being painted by calling to Refresh() method, as you can see in the code below:
Code: Select all
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
//nf
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
namespace CheckListBox
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;
private DataTable dt1, dt2, dt3;
private DataRow dr1, dr2, dr3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private int i=0;
private int xTime = 0;
private Thread t;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.Label label1;
private Steema.TeeChart.TChart tChart1;
private Steema.TeeChart.Styles.FastLine fastLine1;
private Steema.TeeChart.Styles.FastLine fastLine2;
private Steema.TeeChart.Styles.FastLine fastLine3;
private bool bUseCheckDataSource;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
t = new Thread(new ThreadStart(my_Thread));
bUseCheckDataSource = false;
}//Form1
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.label1 = new System.Windows.Forms.Label();
this.tChart1 = new Steema.TeeChart.TChart();
this.fastLine1 = new Steema.TeeChart.Styles.FastLine();
this.fastLine2 = new Steema.TeeChart.Styles.FastLine();
this.fastLine3 = new Steema.TeeChart.Styles.FastLine();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(496, 368);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 40);
this.button1.TabIndex = 1;
this.button1.Text = "Start Thread";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(608, 368);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 40);
this.button2.TabIndex = 2;
this.button2.Text = "Stop Thread";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// checkBox1
//
this.checkBox1.Location = new System.Drawing.Point(48, 368);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(288, 16);
this.checkBox1.TabIndex = 3;
this.checkBox1.Text = "Use \'CheckDataSource\' ...otherwise plain .Add(x,y)";
//
// label1
//
this.label1.Location = new System.Drawing.Point(48, 400);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(392, 40);
this.label1.TabIndex = 4;
this.label1.Text = "To reproduce the \'System.IndexOutofRangeException\' in System.Windows.Forms.dll ch" +
"eck the checkbox., then click \'Start\' and wait some time ... be patient.";
//
// tChart1
//
//
// tChart1.Axes
//
//
// tChart1.Axes.Bottom
//
//
// tChart1.Axes.Bottom.Labels
//
//
// tChart1.Axes.Bottom.Labels.Font
//
//
// tChart1.Axes.Bottom.Labels.Font.Shadow
//
this.tChart1.Axes.Bottom.Labels.Font.Shadow.Visible = false;
//
// tChart1.Axes.Bottom.Labels.Shadow
//
this.tChart1.Axes.Bottom.Labels.Shadow.Visible = false;
//
// tChart1.Axes.Bottom.Title
//
//
// tChart1.Axes.Bottom.Title.Font
//
//
// tChart1.Axes.Bottom.Title.Font.Shadow
//
this.tChart1.Axes.Bottom.Title.Font.Shadow.Visible = false;
//
// tChart1.Axes.Bottom.Title.Shadow
//
this.tChart1.Axes.Bottom.Title.Shadow.Visible = false;
//
// tChart1.Axes.Depth
//
//
// tChart1.Axes.Depth.Labels
//
//
// tChart1.Axes.Depth.Labels.Font
//
//
// tChart1.Axes.Depth.Labels.Font.Shadow
//
this.tChart1.Axes.Depth.Labels.Font.Shadow.Visible = false;
//
// tChart1.Axes.Depth.Labels.Shadow
//
this.tChart1.Axes.Depth.Labels.Shadow.Visible = false;
//
// tChart1.Axes.Depth.Title
//
//
// tChart1.Axes.Depth.Title.Font
//
//
// tChart1.Axes.Depth.Title.Font.Shadow
//
this.tChart1.Axes.Depth.Title.Font.Shadow.Visible = false;
//
// tChart1.Axes.Depth.Title.Shadow
//
this.tChart1.Axes.Depth.Title.Shadow.Visible = false;
//
// tChart1.Axes.DepthTop
//
//
// tChart1.Axes.DepthTop.Labels
//
//
// tChart1.Axes.DepthTop.Labels.Font
//
//
// tChart1.Axes.DepthTop.Labels.Font.Shadow
//
this.tChart1.Axes.DepthTop.Labels.Font.Shadow.Visible = false;
//
// tChart1.Axes.DepthTop.Labels.Shadow
//
this.tChart1.Axes.DepthTop.Labels.Shadow.Visible = false;
//
// tChart1.Axes.DepthTop.Title
//
//
// tChart1.Axes.DepthTop.Title.Font
//
//
// tChart1.Axes.DepthTop.Title.Font.Shadow
//
this.tChart1.Axes.DepthTop.Title.Font.Shadow.Visible = false;
//
// tChart1.Axes.DepthTop.Title.Shadow
//
this.tChart1.Axes.DepthTop.Title.Shadow.Visible = false;
//
// tChart1.Axes.Left
//
//
// tChart1.Axes.Left.Labels
//
//
// tChart1.Axes.Left.Labels.Font
//
//
// tChart1.Axes.Left.Labels.Font.Shadow
//
this.tChart1.Axes.Left.Labels.Font.Shadow.Visible = false;
//
// tChart1.Axes.Left.Labels.Shadow
//
this.tChart1.Axes.Left.Labels.Shadow.Visible = false;
//
// tChart1.Axes.Left.Title
//
//
// tChart1.Axes.Left.Title.Font
//
//
// tChart1.Axes.Left.Title.Font.Shadow
//
this.tChart1.Axes.Left.Title.Font.Shadow.Visible = false;
//
// tChart1.Axes.Left.Title.Shadow
//
this.tChart1.Axes.Left.Title.Shadow.Visible = false;
//
// tChart1.Axes.Right
//
//
// tChart1.Axes.Right.Labels
//
//
// tChart1.Axes.Right.Labels.Font
//
//
// tChart1.Axes.Right.Labels.Font.Shadow
//
this.tChart1.Axes.Right.Labels.Font.Shadow.Visible = false;
//
// tChart1.Axes.Right.Labels.Shadow
//
this.tChart1.Axes.Right.Labels.Shadow.Visible = false;
//
// tChart1.Axes.Right.Title
//
//
// tChart1.Axes.Right.Title.Font
//
//
// tChart1.Axes.Right.Title.Font.Shadow
//
this.tChart1.Axes.Right.Title.Font.Shadow.Visible = false;
//
// tChart1.Axes.Right.Title.Shadow
//
this.tChart1.Axes.Right.Title.Shadow.Visible = false;
//
// tChart1.Axes.Top
//
//
// tChart1.Axes.Top.Labels
//
//
// tChart1.Axes.Top.Labels.Font
//
//
// tChart1.Axes.Top.Labels.Font.Shadow
//
this.tChart1.Axes.Top.Labels.Font.Shadow.Visible = false;
//
// tChart1.Axes.Top.Labels.Shadow
//
this.tChart1.Axes.Top.Labels.Shadow.Visible = false;
//
// tChart1.Axes.Top.Title
//
//
// tChart1.Axes.Top.Title.Font
//
//
// tChart1.Axes.Top.Title.Font.Shadow
//
this.tChart1.Axes.Top.Title.Font.Shadow.Visible = false;
//
// tChart1.Axes.Top.Title.Shadow
//
this.tChart1.Axes.Top.Title.Shadow.Visible = false;
//
// tChart1.Footer
//
//
// tChart1.Footer.Font
//
//
// tChart1.Footer.Font.Shadow
//
this.tChart1.Footer.Font.Shadow.Visible = false;
//
// tChart1.Footer.Shadow
//
this.tChart1.Footer.Shadow.Visible = false;
//
// tChart1.Header
//
//
// tChart1.Header.Font
//
//
// tChart1.Header.Font.Shadow
//
this.tChart1.Header.Font.Shadow.Visible = false;
this.tChart1.Header.Lines = new string[] {
"TeeChart"};
//
// tChart1.Header.Shadow
//
this.tChart1.Header.Shadow.Visible = false;
//
// tChart1.Legend
//
//
// tChart1.Legend.Font
//
//
// tChart1.Legend.Font.Shadow
//
this.tChart1.Legend.Font.Shadow.Visible = false;
//
// tChart1.Legend.Title
//
//
// tChart1.Legend.Title.Font
//
this.tChart1.Legend.Title.Font.Bold = true;
//
// tChart1.Legend.Title.Font.Shadow
//
this.tChart1.Legend.Title.Font.Shadow.Visible = false;
//
// tChart1.Legend.Title.Pen
//
this.tChart1.Legend.Title.Pen.Visible = false;
//
// tChart1.Legend.Title.Shadow
//
this.tChart1.Legend.Title.Shadow.Visible = false;
this.tChart1.Location = new System.Drawing.Point(192, 32);
this.tChart1.Name = "tChart1";
//
// tChart1.Panel
//
//
// tChart1.Panel.Shadow
//
this.tChart1.Panel.Shadow.Visible = false;
this.tChart1.Series.Add(this.fastLine1);
this.tChart1.Series.Add(this.fastLine2);
this.tChart1.Series.Add(this.fastLine3);
this.tChart1.Size = new System.Drawing.Size(592, 304);
//
// tChart1.SubFooter
//
//
// tChart1.SubFooter.Font
//
//
// tChart1.SubFooter.Font.Shadow
//
this.tChart1.SubFooter.Font.Shadow.Visible = false;
//
// tChart1.SubFooter.Shadow
//
this.tChart1.SubFooter.Shadow.Visible = false;
//
// tChart1.SubHeader
//
//
// tChart1.SubHeader.Font
//
//
// tChart1.SubHeader.Font.Shadow
//
this.tChart1.SubHeader.Font.Shadow.Visible = false;
//
// tChart1.SubHeader.Shadow
//
this.tChart1.SubHeader.Shadow.Visible = false;
this.tChart1.TabIndex = 5;
//
// tChart1.Walls
//
//
// tChart1.Walls.Back
//
//
// tChart1.Walls.Back.Shadow
//
this.tChart1.Walls.Back.Shadow.Visible = false;
//
// tChart1.Walls.Bottom
//
//
// tChart1.Walls.Bottom.Shadow
//
this.tChart1.Walls.Bottom.Shadow.Visible = false;
//
// tChart1.Walls.Left
//
//
// tChart1.Walls.Left.Shadow
//
this.tChart1.Walls.Left.Shadow.Visible = false;
//
// tChart1.Walls.Right
//
//
// tChart1.Walls.Right.Shadow
//
this.tChart1.Walls.Right.Shadow.Visible = false;
//
// fastLine1
//
//
// fastLine1.LinePen
//
this.fastLine1.LinePen.Color = System.Drawing.Color.Red;
//
// fastLine1.Marks
//
//
// fastLine1.Marks.Callout
//
this.fastLine1.Marks.Callout.Arrow = this.fastLine1.Marks.Arrow;
this.fastLine1.Marks.Callout.ArrowHead = Steema.TeeChart.Styles.ArrowHeadStyles.None;
this.fastLine1.Marks.Callout.ArrowHeadSize = 8;
//
// fastLine1.Marks.Callout.Brush
//
this.fastLine1.Marks.Callout.Brush.Color = System.Drawing.Color.Black;
this.fastLine1.Marks.Callout.Distance = 0;
this.fastLine1.Marks.Callout.Draw3D = false;
this.fastLine1.Marks.Callout.Length = 10;
this.fastLine1.Marks.Callout.Style = Steema.TeeChart.Styles.PointerStyles.Rectangle;
//
// fastLine1.Marks.Font
//
//
// fastLine1.Marks.Font.Shadow
//
this.fastLine1.Marks.Font.Shadow.Visible = false;
this.fastLine1.Title = "fastLine1";
//
// fastLine1.XValues
//
this.fastLine1.XValues.DataMember = "X";
this.fastLine1.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending;
//
// fastLine1.YValues
//
this.fastLine1.YValues.DataMember = "Y";
//
// fastLine2
//
//
// fastLine2.LinePen
//
this.fastLine2.LinePen.Color = System.Drawing.Color.Green;
//
// fastLine2.Marks
//
//
// fastLine2.Marks.Callout
//
this.fastLine2.Marks.Callout.Arrow = this.fastLine2.Marks.Arrow;
this.fastLine2.Marks.Callout.ArrowHead = Steema.TeeChart.Styles.ArrowHeadStyles.None;
this.fastLine2.Marks.Callout.ArrowHeadSize = 8;
//
// fastLine2.Marks.Callout.Brush
//
this.fastLine2.Marks.Callout.Brush.Color = System.Drawing.Color.Black;
this.fastLine2.Marks.Callout.Distance = 0;
this.fastLine2.Marks.Callout.Draw3D = false;
this.fastLine2.Marks.Callout.Length = 10;
this.fastLine2.Marks.Callout.Style = Steema.TeeChart.Styles.PointerStyles.Rectangle;
//
// fastLine2.Marks.Font
//
//
// fastLine2.Marks.Font.Shadow
//
this.fastLine2.Marks.Font.Shadow.Visible = false;
this.fastLine2.Title = "fastLine2";
//
// fastLine2.XValues
//
this.fastLine2.XValues.DataMember = "X";
this.fastLine2.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending;
//
// fastLine2.YValues
//
this.fastLine2.YValues.DataMember = "Y";
//
// fastLine3
//
//
// fastLine3.LinePen
//
this.fastLine3.LinePen.Color = System.Drawing.Color.Yellow;
//
// fastLine3.Marks
//
//
// fastLine3.Marks.Callout
//
this.fastLine3.Marks.Callout.Arrow = this.fastLine3.Marks.Arrow;
this.fastLine3.Marks.Callout.ArrowHead = Steema.TeeChart.Styles.ArrowHeadStyles.None;
this.fastLine3.Marks.Callout.ArrowHeadSize = 8;
//
// fastLine3.Marks.Callout.Brush
//
this.fastLine3.Marks.Callout.Brush.Color = System.Drawing.Color.Black;
this.fastLine3.Marks.Callout.Distance = 0;
this.fastLine3.Marks.Callout.Draw3D = false;
this.fastLine3.Marks.Callout.Length = 10;
this.fastLine3.Marks.Callout.Style = Steema.TeeChart.Styles.PointerStyles.Rectangle;
//
// fastLine3.Marks.Font
//
//
// fastLine3.Marks.Font.Shadow
//
this.fastLine3.Marks.Font.Shadow.Visible = false;
this.fastLine3.Title = "fastLine3";
//
// fastLine3.XValues
//
this.fastLine3.XValues.DataMember = "X";
this.fastLine3.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending;
//
// fastLine3.YValues
//
this.fastLine3.YValues.DataMember = "Y";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(824, 453);
this.Controls.Add(this.tChart1);
this.Controls.Add(this.label1);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void InitializeChart()
{
tChart1.AutoRepaint = false; //autorepaint to false
dt1 = new DataTable();
dt2 = new DataTable();
dt3 = new DataTable();
dt1.Columns.Add(new DataColumn("XValues", System.Type.GetType("System.Double")));
dt1.Columns.Add(new DataColumn("YValues", System.Type.GetType("System.Double")));
dt1.Columns.Add(new DataColumn("Labels", System.Type.GetType("System.String")));
dt2.Columns.Add(new DataColumn("XValues", System.Type.GetType("System.Double")));
dt2.Columns.Add(new DataColumn("YValues", System.Type.GetType("System.Double")));
dt2.Columns.Add(new DataColumn("Labels", System.Type.GetType("System.String")));
dt3.Columns.Add(new DataColumn("XValues", System.Type.GetType("System.Double")));
dt3.Columns.Add(new DataColumn("YValues", System.Type.GetType("System.Double")));
dt3.Columns.Add(new DataColumn("Labels", System.Type.GetType("System.String")));
}
private void Form1_Load(object sender, System.EventArgs e)
{
InitializeChart();
//lock(fastLine1){DataSource = dt1;}
fastLine1.DataSource = dt1;
fastLine1.XValues.DataMember = dt1.Columns["XValues"].ToString();
fastLine1.YValues.DataMember = dt1.Columns["YValues"].ToString();
fastLine1.LabelMember = dt1.Columns["Labels"].ToString();
fastLine1.CheckDataSource();
fastLine2.DataSource = dt2;
fastLine2.XValues.DataMember = dt2.Columns["XValues"].ToString();
fastLine2.YValues.DataMember = dt2.Columns["YValues"].ToString();
fastLine2.LabelMember = dt2.Columns["Labels"].ToString();
fastLine2.CheckDataSource();
fastLine3.DataSource = dt3;
fastLine3.XValues.DataMember = dt3.Columns["XValues"].ToString();
fastLine3.YValues.DataMember = dt3.Columns["YValues"].ToString();
fastLine3.LabelMember = dt3.Columns["Labels"].ToString();
fastLine3.CheckDataSource();
}
private void button1_Click(object sender, System.EventArgs e)
{
StartStopReadHID();
}
private void button2_Click(object sender, System.EventArgs e)
{
StartStopReadHID();
}
/// <summary>
/// Used to start/stop the thread function
/// </summary>
private void StartStopReadHID()
{
if(t.ThreadState.ToString() == "Unstarted")
{
// Start the thread
// Upon start of the thread, my_Thread() executes
t.Start();
t.Join(1000);
Thread.Sleep(0);
}
else
{
if(t.ThreadState.ToString() == "Running")
{ //Stop/Abort the thread
Thread.Sleep(1);
t.Abort();
t.Join();
}
}
}//StartStopReadHID
/// <summary>
/// This happens when the Thread is started.
/// </summary>
private void my_Thread()
{
while(true)
{
Random rnd1 = new Random();
Random rnd2 = new Random();
Random rnd3 = new Random();
dr1 = dt1.NewRow();
dr1["XValues"] = xTime;
dr1["YValues"] = rnd1.Next(100);
dt1.Rows.Add(dr1);
dr2 = dt2.NewRow();
dr2["XValues"] = xTime;
dr2["YValues"] = rnd2.Next(200);
dt2.Rows.Add(dr2);
dr3 = dt3.NewRow();
dr3["XValues"] = xTime;
dr3["YValues"] = rnd3.Next(50);
dt3.Rows.Add(dr3);
if(checkBox1.Checked)
{
fastLine1.CheckDataSource();
fastLine2.CheckDataSource();
fastLine3.CheckDataSource();
}
else
{
fastLine1.Add(xTime,rnd1.Next(100));
fastLine2.Add(xTime,rnd2.Next(200));
fastLine3.Add(xTime,rnd3.Next(50));
}
xTime++;
tChart1.Refresh(); //repaint the chart when all points in position
}//while
}
}
}
There's no problem with our news server. You should just add www.steema.net asa news server to your newsreader and set it up with the default setting.I tried to download the project (as-is) to the link you gave but it always says: Could not send. Sender not specified. Check your news configuration.....
Best Regards,
Narcís Calvet / 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 |