I am attempting to plot two graphs simultaneously using multi threading, however, the charts return an error message stating "Control 'chart1' accessed from a thread other than the thread it was created on.". I believe this can be resolved using "Invoke", but I am unsure of how this can be done.
Here is simplified code for one graph and one thread:
private void button1_Click(object sender, EventArgs e)
{
Thread th = new Thread(thread);
th.Start();
}
public void graph(List<double> xlist, List<double> ylist)
{
chart1.Series["1"].Points.DataBindXY(xlist, ylist);
}
public void thread()
{
List<double> xlist = new List<double>();
List<double> ylist = new List<double>();
//Assume xlist and ylist have a range of numerical elements
graph(xlist, ylist);
}
Any help would be appreciated.