Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

WaveformGraph Red X Error

Using NationalInstruments.UI.WindowsForms.WaveformGraph with PlotY in a try catch block I get the following error regularly:

System.ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
at System.Array.BinarySearch(Array array, Int32 index, Int32 length, Object value, IComparer comparer)
at aF.Clip(Double xmin, Double ymin, Double xmax, Double ymax, Double[] xData, Double[] yData, Int32 dataLength, Double[]& clippedXData, Double[]& clippedYData, Int32[]& unclippedDataIndices)
at aE.a(u , u , Rectangle , Boolean , Boolean , PointF[]& )
at as.Map(Rectangle bounds, PointF[]& mappedData)
at as.DrawForeground(ComponentDrawArgsInternal args)
at NationalInstruments.Restricted.ControlElement.a(ComponentDrawArgsInternal , Rectangle , Boolean )
at NationalInstruments.Restricted.ControlElement.DrawChildren(ComponentDrawArgsInternal args, Rectangle clipRectangle)
at NationalInstruments.Restricted.ControlElement.a(ComponentDrawArgsInternal , Rectangle , Boolean )
at NationalInstruments.Restricted.ControlElement.DrawChildren(ComponentDrawArgsInternal args, Rectangle clipRectangle)
at NationalInstruments.Restricted.ControlElement.a(ComponentDrawArgsInternal , Rectangle , Boolean )
at NationalInstruments.Restricted.ControlElement.DrawChildren(ComponentDrawArgsInternal args, Rectangle clipRectangle)
at NationalInstruments.Restricted.ControlElement.a(ComponentDrawArgsInternal , Rectangle , Boolean )
at NationalInstruments.Restricted.ControlElement.a(ComponentDrawArgsInternal , Rectangle )
at NationalInstruments.Restricted.ControlElement.Paint(PaintEventArgs e)
at NationalInstruments.UI.WindowsForms.ControlBase.OnPaint(PaintEventArgs e)

I am using PlotY in a try catch block but still get the error regularly.
0 Kudos
Message 1 of 6
(4,376 Views)
Which version of Measurement Studio are you using? Also, could you please post either a snippet of code or a small test project that demonstrates how to reproduce this behavior? Thanks.

- Elton
0 Kudos
Message 2 of 6
(4,371 Views)
I am using 7.1.

I will post the exact code later, but all I am doing is calling PlotY with an Array of values I am getting from a DAQ board 5 times a second. I sometimes get bad reads from the board so I make sure the aray is the expected size before I plot it.
0 Kudos
Message 3 of 6
(4,360 Views)
That should definitely work, so I will need to see the code to tell what's going on. One thing I was wondering is how you're getting the data from DAQ? Specifically, are you getting the data synchronously or asynchronously? If you're getting data asynchronously and you're plotting data from a thread that's not the UI thread, that could be part of the problem.

- Elton
0 Kudos
Message 4 of 6
(4,351 Views)
Elton,

You are the man! It was a threading issue. I was calling it synch but using the a System timer. I changed it to a windows.forms.timer so it would run in the same thread and it ran for 3 hours without an error.

Thanks for your help.
0 Kudos
Message 5 of 6
(4,339 Views)
No problem, I'm glad that things are working for you now.

Just to clarify, the problem is that Windows Forms controls are not thread-safe. Notice that the class overviews of all .NET Framework and Measurement Studio Windows Forms controls have a thread safety section that states:

"Only the following members are safe for multithreaded operations: BeginInvoke, EndInvoke, Invoke, InvokeRequired, and CreateGraphics."

The way that you changed it works, but in case you're curious about other approaches, see the .NET Quickstart article "Making procedure calls across thread boundaries".

- Elton
Message 6 of 6
(4,330 Views)