I keep getting a crash in ListFiller:Fill

Oystein Bjorke 6 years ago 0
This discussion was imported from CodePlex

willmoore88 wrote at 2013-09-18 16:30:

I keep getting random crashed in the Fill function in ListFiller.cs. I get the Collection was modified; enumeration operation may not execute error on IEnumerable source in the foreach (var sourceItem in staticSource) line.

I have had other similar problems within the rest of the library, where because I update datasets quite often, obviously before the last has been written to screen, the array has been updated before it has finished iterating through it! Normally, casting ToArray() // ToList() has solved this.

objo wrote at 2013-09-20 09:18:

Is this problem solved when you use ToArray/ToList in your application?
I would like to avoid adding this to OxyPlot, as I guess there may be a performance hit for large datasets.

Can we lock the collection's syncroot while updating the plot?

willmoore88 wrote at 2013-09-20 09:29:

It has been solved where I've used it in other places, but obviously can't here.
I'll have a look at syncroot, thanks.

willmoore88 wrote at 2013-10-07 14:02:

The way I seem to have solved this was my using a ConcurrentQueue instead of a List as my ItemsSource. ConcurrentQueue's are thread safe and so have avoided the issue where the ItemsSource was getting updated whilst that function was looping. I think if I had implemented the same thing throughout my application then maybe I wouldn't have needed to do any ToArray's. Hopefully if I have time i'll go back and undo all of that - as you say, large datasets maybe hit and I do have HUGE datasets. Maybe something to look at in your tutorials? ConcurrentQueue's are no harder to implement than lists but are thread safe :-)