System.InvalidOperationException - OnKeyDown

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

krzysiek_jrd wrote at 2014-07-08 10:21:

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,

objo wrote at 2014-07-10 13:15:

The 'a' command seems to work in the examples. Can you provide more information how to reproduce this?

wbidus wrote at 2014-07-14 10:03:

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.

Slxe wrote at 2014-07-14 16:27:

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).