Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
40
ObservableCollectionExtended: Destination array is not long enough to coy all the items in the collection. Check array index and length
posted

Hey guys,

We are recieving data from socket, and displaying it on a listbox. Idea was to limit the number of oncollectionchanges, to prevent dispatcher hangs. So we switched to "ObservableCollectionExtended", incoming data is very fast about 3000 messages per second, hence we tried to simulate this (in the attached sample with multiple producers on timers)

We are using following simple logic to update the observable collection periodically using insertrange, and removerange (to limit the number of records in the observable collection to 2 million. After about 5 mins of run, ObservableCollectionExtended throws an unhandled exception: Destination array is not long enough to coy all the items in the collection. Check array index and length (sample code is attached).

lock (_locSync)

{

try

{

if (_orderList.Count > 0)

{

OrderCollection.BeginUpdate();

OrderCollection.InsertRange(0, _orderList);

Int32 count = OrderCollection.Count;

Int32 excess = count - _maxLimit;

if (count > _maxLimit)

OrderCollection.RemoveRange((_maxLimit - 1), excess);

OrderCollection.EndUpdate();

_orderList.Clear();

}

}

catch (Exception ee) { String s = String.Empty; }

}

Could you help please? Code is running on .Net framework 4.5.2.

FastData - Copy.zip

Regards,

Vinay