I am having a chart with two series primary and secondary y-axis.I want to add values to chart using delegates.When I am adding,getting "cross thread operation not valid" exception. Please refer my code below.
public delegate void SetTextDel(string Xvalue,double Y1value,double
Y2Value);
Thread Thread1=new Thread(createGraph);
private void SetText(string XValue,double Y1Value,double Y2Value)
{
if (this.chart1.InvokeRequired)
{
this.chart1.Series[0].Points.AddXY(XValue, Y1Value);
this.chart1.Series[1].Points.AddXY(XValue, Y2Value);
}
}
private void createGraph()
{
while(true)
{
string time;
int Y1value =0;
int Y2value =0;
time="abc";
Y1value = 10;
Y2value = 20;
SetTextDel = new SetTextDel(SetText);
SetText(time,oilvalue,tempvalue);
Y1value +=5;
Y2value +=5;
}
}
private void startbtn_Click(object sender, EventArgs e)
{
Thread1.Start();
}