Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem adding plots to the graph dynamically

Hi,
I'm trying to add/remove plots to a  graph dynamically but are geting the error below. What am i doing wrong? Could you please give me an example of how i should do this? I'm using MS 8.0.1 and VS 2005 C#.
 
My code snippets:
Adding a plot:
timestampGraph.Plots.Add(new NationalInstruments.UI.WaveformPlot());

Appending plot data:
timestampGraph.Plots[plotIndex].PlotYAppend(timestampDiff);

Clearing plot data:
timestampGraph.Plots[plots.FindIndex(delegate(TimestampPlotInfo p) { return (p.source == source); })].ClearData();

Exception:
+  $exception {"Collection was modified; enumeration operation may not execute."} System.Exception {System.InvalidOperationException}
Callstack:
  StackTrace "   at System.Collections.Hashtable.HashtableEnumerator.MoveNext()\r\n   at NationalInstruments.UI.Internal.dv.a(ComponentDrawArgsInternal A_0, RectangleF[] A_1)\r\n   at NationalInstruments.UI.Internal.dv.b(ComponentDrawArgsInternal A_0)\r\n   at NationalInstruments.Restricted.ControlElement.a(ComponentDrawArgsInternal A_0, Rectangle A_1, Boolean A_2)\r\n   at NationalInstruments.Restricted.ControlElement.DrawChildren(ComponentDrawArgsInternal args, Rectangle clipRectangle)\r\n   at NationalInstruments.Restricted.ControlElement.a(ComponentDrawArgsInternal A_0, Rectangle A_1, Boolean A_2)\r\n   at NationalInstruments.Restricted.ControlElement.DrawChildren(ComponentDrawArgsInternal args, Rectangle clipRectangle)\r\n   at NationalInstruments.Restricted.ControlElement.a(ComponentDrawArgsInternal A_0, Rectangle A_1, Boolean A_2)\r\n   at NationalInstruments.Restricted.ControlElement.a(ComponentDrawArgsInternal A_0, Rectangle A_1)\r\n   at NationalInstruments.Restricted.ControlElement.Paint(PaintEventArgs e)\r\n   at NationalInstruments.UI.WindowsForms.ControlBase.OnPaint(PaintEventArgs e)\r\n   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)\r\n   at System.Windows.Forms.Control.WmPaint(Message& m)\r\n   at System.Windows.Forms.Control.WndProc(Message& m)\r\n   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\r\n   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)\r\n   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n   at System.Windows.Forms.Application.Run(Form mainForm)\r\n   at AdrRecorder2Client.Program.Main() in C:\\Project\\Autoliv\\AdrRecorder2Client\\Applications\\AdrRecorder2Client\\Program.cs:line 19" string
 
 
Ps. It's quite annoying that you can preview the post, push the back button to edit something and all that you have written is wiped! Ds.
0 Kudos
Message 1 of 3
(3,119 Views)
In order to make a workaround i tried creating several static plots and initialize them as non-visual and then make he ones i need to use viual as i go along. The puzzling thing is that i actually got the same error here as well, it was able to plot for a few seconds and then the exception was raised.
 
A stupid question but the plot function is thread-safe right???
0 Kudos
Message 2 of 3
(3,104 Views)
Perhaps the problem is that you're accessing the graph from a thread other than that which it was created on - look at the places where you access the graph and see if any could be from a different thread (e.g., as a result of a network callback, or unsychronized timer callback).
0 Kudos
Message 3 of 3
(3,080 Views)