-1

As part of a project, I created a program that collects external data at specific intervals (most often 1/second), and plot a graph out of it. Several times, while leaving the program running overnight as a stress test, the program sometimes encounter an ArgumentOutOfRangeException. Here is part of the exception output:

System.ArgumentOutOfRangeException:
Parameter: index
    at
System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument
argument, ExceptionResource resource)
    at System.Collections.Generic.List`1.get_Item(Int32 index)
    at Macro_GUI.Macro_GUI.ChartReload_Part2()
    at Macro_GUI.Macro_GUI.ChartReload()
    at Macro_GUI.Macro_GUI.ScreenDataUpdate()
    at Macro_GUI.Macro_GUI.ScreenTimer_Tick(Object sender, EventArgs e)
    at System.Windows.Forms.Timer.OnTick(EventArgs e)
    at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)

ChartReload_Part2() is part of the continous re-drawing of the graph. This time the error happened after a collection time somewhat longer than 17 hours.

Reading about ArgumentOutOfRangeException, it seems to most often have something to do with the Capacity of a List Collection (there are several uses of a List in the method). Anyone know if I am on the right track or if the problem is something else? Or have I given to little information for anyone to help?

Netsrym
  • 11
  • 1
  • 1

1 Answers1

0

When you read the documentation:

Exceptions

ArgumentOutOfRangeException

index is less than 0.

-or-

index is equal to or greater than Count.

Two possibilities:

  • either you are really out of bounds
  • either you crossed Int32.MaxValue and therefore next value becomes negative

As you're letting it run overnight, it's highly possible you have so many items that you're encountering the second possiblity.

Considerations:

  • a graph on a screen can't be Int32.MaxValue unless it's scrollable
  • persist the data somehow on storage, summarize it, read it on the fly,
    • i.e. a list with billions of items should sound like a red flag to you
  • check for alternative libraries, there might be some that already do that hard work for you
aybe
  • 15,516
  • 9
  • 57
  • 105