I am trying to enqueue values on to a queue and it works fine. When the program runs for few hours, I get the following error
System.ArgumentException: length
at System.Array.Copy (System.Array sourceArray, System.Int32 sourceIndex, System.Array destinationArray, System.Int32 destinationIndex, System.Int32 length) [0x000c3] in <f56c876907e742b0aa586f051fcce845>:0
at System.Collections.Generic.Queue`1[T].SetCapacity (System.Int32 capacity) [0x0001e] in <ccafeb0e74bd436bb84e5138772c2bb0>:0
at System.Collections.Generic.Queue`1[T].Enqueue (T item) [0x0003e] in <ccafeb0e74bd436bb84e5138772c2bb0>:0
at VSCaptureMP.MPudpclient.ExportWaveToCSV () [0x0010a] in <f1c552d4f5b3424d9438ec1100580a9d>:0
at VSCaptureMP.MPudpclient.PollPacketDecoder (System.Byte[] packetbuffer, System.Int32 headersize) [0x00121] in <f1c552d4f5b3424d9438ec1100580a9d>:0
I am enqueuing values every hundred millisecond and I have a task which dequeues from the queue. The queue is not increasing and its count lies between 250 and 500. What could be the issue? I tried ConcurrentQueue as well. The program then ran longer though but after 12 hours it gave the following exception:
at (wrapper alloc) System.Object.AllocVector(intptr,intptr)
at System.Collections.Concurrent.ConcurrentQueue1+Segment[T]..ctor (System.Int32 boundedLength) [0x00006] in <f56c876907e742b0aa586f051fcce845>:0
at System.Collections.Concurrent.ConcurrentQueue1[T].EnqueueSlow (T item) [0x00051] in <f56c876907e742b0aa586f051fcce845>:0
at System.Collections.Concurrent.ConcurrentQueue`1[T].Enqueue (T item) [0x00010] in <f56c876907e742b0aa586f051fcce845>:0
From what you describe I assume your underlying problem may be caused by a race condition. Queues like lists use arrays internally and resize them when needed. They do it in powers of two, e.g. 128, 256 and 512, which coincidentally aligns with your count boundaries. Resizing means creating a new array (smaller or bigger) and copying the content to the new array, hands the Array.Copy() call.
From the Callstack I can see that the queue is resized during an Enqueue operation. Apparently in the mean-time the dequeue operation already shrunk the internal array causing the argument exception. Try using a ConcurrentQueue instead and check again.
Edit: Link to latest documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With