System.InvalidOperationException - OnKeyDown

Jul 8, 2014 at 9:21 AM
Hi All,

I'm plotting real time data using OxyPlot, everything seems to be working great apart of the exception in 'PlotModel.ResetAllAxes' method. The exceptions occurs each time I press 'a' key when the focus is on the OxyPlot area.

Can you please advice how to fix this issue?
OxyPlot.dll!OxyPlot.PlotModel.ResetAllAxes() Line 1237  C#
 OxyPlot.dll!OxyPlot.PlotCommands.HandleReset(OxyPlot.IPlotView view) Line 235  C#
 OxyPlot.dll!OxyPlot.PlotCommands..cctor.AnonymousMethod__6(OxyPlot.IPlotView view, OxyPlot.IController controller, OxyPlot.OxyKeyEventArgs args) Line 44   C#
 OxyPlot.dll!OxyPlot.DelegatePlotCommand<OxyPlot.OxyKeyEventArgs>..ctor.AnonymousMethod__0(OxyPlot.IView v, OxyPlot.IController c, OxyPlot.OxyKeyEventArgs e) Line 47   C#
 OxyPlot.dll!OxyPlot.DelegateViewCommand<OxyPlot.OxyKeyEventArgs>.Execute(OxyPlot.IView view, OxyPlot.IController controller, OxyPlot.OxyInputEventArgs args) Line 76   C#
 OxyPlot.dll!OxyPlot.ControllerBase.HandleCommand(OxyPlot.IViewCommand command, OxyPlot.IView view, OxyPlot.OxyInputEventArgs args) Line 533    C#
 OxyPlot.dll!OxyPlot.ControllerBase.HandleKeyDown(OxyPlot.IView view, OxyPlot.OxyKeyEventArgs args) Line 348    C#
 OxyPlot.Wpf.dll!OxyPlot.Wpf.PlotView.OnKeyDown(System.Windows.Input.KeyEventArgs e) Line 588   C#
Many thanks,
Krzysztof
Coordinator
Jul 10, 2014 at 12:15 PM
The 'a' command seems to work in the examples. Can you provide more information how to reproduce this?
Jul 14, 2014 at 9:03 AM
Edited Jul 14, 2014 at 10:12 AM
In my case this error occurs only after moving the chart. when i press 'a' key just after plot loads, nothing happens. When I move the plot and press 'a', exception appears.


An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll

Additional information: Collection was modified; enumeration operation may not execute.

Edit. I am using oxyplot on WPF.
Jul 14, 2014 at 3:27 PM
Yea I've gotten that error a few times myself, but it generally cleans itself up. That's happening because you're moving or altering OxyPlots display, which is somewhat based on the data in each series points list, at the same time that data is being added to those points lists. I found it all depends on how often you're refreshing the displayed chart (calling InvalidatePlot(true)), in playing with it myself, in WinForms though, I've found generally anything under about 200ms starts getting pretty buggy because of these conflicts. Also keep in mind that that includes when you add data to the points lists, as zooming and panning calls InvalidatePlot(false).