i wrote this code to create a chart(by using wpf toolkit charting) but I receive this error,
private void Window_Loaded(object sender, RoutedEventArgs e)
{
LoadLineChartData2();
}
private void LoadLineChartData2()
{
time= new Timer(10);
time.Elapsed += new ElapsedEventHandler(time_Elapsed);
time.Start();
}
Timer time;
List<KeyValuePair<double, int>> list = new List<KeyValuePair<double, int>>();
int index = 0;
void time_Elapsed(object sender, ElapsedEventArgs e)
{
list.Add(new KeyValuePair<double,int>(1.0/int.Parse(e.SignalTime.Second.ToString()),index++));
this.Dispatcher.Invoke(new Action(()=> {
((System.Windows.Controls.DataVisualization.Charting.LineSeries)mcChart.Series[0]).ItemsSource = list;
if (index>200)
{
time.Stop();
}
}));
}
erorr: Collection was modified; enumeration operation may not execute.
what is the error and how I can dynamically add points??