Won't Fix
Last Updated: 26 May 2020 15:27 by Petar
Vladimir
Created on: 13 Apr 2020 12:44
Category: ChartView
Type: Bug Report
0
ChartView: InvalidOperationException is thrown when a property changed notification is raised while continously adding new data items in Timer's Ellapsed event.

" Collection was modified; enumeration operation may not execute.'" - The exception is observed when the CLR exceptions are enabled from Visual Studio. 

Edit:

The Ellapsed event handler of the Timer is executed in background thread but modifying chart data in a background thread is considered bad practice which is not supported by our component. This is the reason we are declining this bug report.

General solution is to schedule the data update to happen on the UI thread with Dispatcher. When in ViewModel, the following code can be used:

        private void OnTimerElapsed(object sender, ElapsedEventArgs e)
        {
            ViewModelBase.InvokeOnUIThread(() =>
            {
                for (int i = 0; i < Items.Count; i++)
                {
                    Items[i].X += (_random.NextDouble() - 0.5) * 0.1;
                    Items[i].Y += (_random.NextDouble() - 0.5) * 0.1;
                }
            });
        }
1 comment
Petar
Posted on: 26 May 2020 15:27
We have changed the status of this issue from Unplanned to 'Won't fix' because this is unsupported scenario for this control. We have updated the description with more information and workaround.