I have a C# Chart Control and I data bind it like so.
chart.Series[0].Points.DataBindXY(xAxis, yAxis);
where xAxis is List<String> and yAxis is List<Double>
On another thread xAxis, and yAxis are constantly updated (Multiple calls to .Add())
However the chart does not update unless I call DataBindXY() again, however this seems to cause issue because every once and a while i get
Error: "Collection was modified; enumeration operation may not execute."
Which at some point causes my program to crash with
Error: "system.reflection.targetinvocationexception' occurred in mscorlib.dll"
-Is there something im missing as far as updating? or should I be doing this diffrently, let me know if you need more information.
You need to add locking or synchronization both in your update method and your DataBindXY method. You cannot modify a List and read it at the same time, because operations on Lists are not thread safe.
I’d recommend reading this (or one of the many, many other) introductions on thread synchronization in C#: http://msdn.microsoft.com/en-us/library/ms173179.aspx
EDIT: Here is an example of how to do this: