Choyee Posted July 9, 2009 Report Posted July 9, 2009 Hi, I made a real time chart binding ItemsSource to a ObservablCollection with a limited buffer size. I used Dispatcher.Invoke method for removing and adding items to keep the buffer size. It worked fine until I added a conditional attribute to the chart. It seemed it throws this TargetInvocationException when a new data meets the condition. Am I using this wrong? int buffersize = 20; ObservableCollection <ChartData> DataSource = new ObservableCollection<ChartData>(); delegate void RemoveAtListArrayDelegate(int index); delegate void AddListArrayDelegate(ChartData cd); public void SetRunChart() { RunChart.Animation.OnDataChange = false; RunChart.ItemsSource = DataSource; SeriesAttributes sa = new SeriesAttributes("Data"); sa.Gallery = Gallery.Line; RunChart.Series.Add(sa); RunChart.AxisX.Labels.BindingPath = "XValue"; RunChart.AxisY.ForceZero = true; } public void AddData(ChartData cd) { if (DataSource.Count > buffersize) { RemoveAtListArrayDelegate removeItem = new RemoveAtListArrayDelegate(DataSource.RemoveAt); Dispatcher.Invoke(removeItem, new object[] { 0 }); } AddListArrayDelegate addItem = new AddListArrayDelegate(DataSource.Add); Dispatcher.Invoke(addItem, new object[] { cd }); } Thanks. p.s. I used Google Chrome for the last post "ZoomMode.Off, it didn't work", but apparently Chrome didn't support editing tool bar as IE does. Sorry for the messed message. It's about implementing a countinuous zooming method. Quote
JuanC Posted July 13, 2009 Report Posted July 13, 2009 We have been unable to reproduce the problem in a sample app where we can add and remove buttons using an ObservableCollection, we tested adding points that do and do not meet the conditions as well as removing points and it seemed to work fine. Note that we executed these in the UI thread directly and not using Dispatcher.Invoke Can you try to isolate a test case in a separate app? You might be able reproduce it using dummy data. Regards, JuanC Quote
Choyee Posted July 15, 2009 Author Report Posted July 15, 2009 Hi, I've isolated this case in a separate application which is attatched. Have you tried to remove the first item in an ObservablCollection array not only adding new one? Try attatched app with and without the statement for removing the first item in the array. (The first item has to be removed to keep the size of displaying points.) I don't know why but it seems the execption is thrown when the first item is removed. Without using condiotional attributes, it really works fine. What should I do to avoid this conflict? Thank, Choyee Quote
JuanC Posted July 17, 2009 Report Posted July 17, 2009 We have fixed the bug in build 3484 or later. JuanC Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.