Under review

Thread safety and RenderPoints

Nick Donais 4 years ago • updated 4 years ago 4
So I've seen the error a few times, mainly when the plot is trying to update and data is being added to the series:

> System.InvalidOperationException occurred
> HResult=-2146233079
> Message=Collection was modified; enumeration operation may not execute.
> Source=mscorlib
> StackTrace:
> at System.Collections.Generic.List`1.Enumerator.MoveNextRare()

Seems to be because ICollection is being used here:
Would it be better to use one of the concurrent collects for this?
Under review
Have you tried using the  `SyncRoot` property on the `PlotModel` to synchronize the updates? Bound collections should not be changed while the plot is updating, I think.
I've experienced this issue a quite a few times during testing, but only if I was adding data and refreshing the chart too fast (under 500ms). It seems to be coming back now in the control I put together that has a custom legend that allows the user to show/hide series easily, and if the plot is being updated at the same time the user clicks show/hide it's shown the error on the plot model for under a second, or even crashed the application.

The main reason I brought up using Concurrent Collections over normal collections is because I'm using OxyPlot currently for real time data, so it's always possible the chart will be updated (from either the set interval or any of the calls that update it, like show or hiding a series, in this event for example) as data is being added into the series on it.

I didn't even know this SyncRoot property existed, I'll look at it more and let you know, Thanks!
Did SyncRoot solve this issue for you?  I'm running into the same issue using real time data.
Yes and no, I still have to limit adding new data to around every 500ms, any faster and I start to see flickering and the error pop up. Honestly I think Concurrent Collections would be a better fix that a lock object for the plot data. Sadly I don't have extra time right now to try and play with the source code >_<.