Hi. I am working with data that is generated every second. I am trying to use ConcurrentQueue to enqueue those contents. I have added a Task which checks whether the queue count is greater than 500. If it is greater than 500, it dequeues the content to an array and I send the array. This is the how my application works. But after running for a few hours, I got the following message:
at (wrapper alloc) System.Object.AllocVector(intptr,intptr)
at System.Collections.Concurrent.ConcurrentQueue`1+Segment[T]..ctor (System.Int32 boundedLength) [0x00006] in <f56c876907e742b0aa586f051fcce845>:0
at System.Collections.Concurrent.ConcurrentQueue`1[T].EnqueueSlow (T item) [0x00051] in <f56c876907e742b0aa586f051fcce845>:0
at System.Collections.Concurrent.ConcurrentQueue`1[T].Enqueue (T item) [0x00010] in <f56c876907e742b0aa586f051fcce845>:0
Please help me out. Give me somme suggestions to solve this problem. Should I use System.Generics.Queue instead of ConcurrentQueue?
I am using the following steps:
1. Read data from serial port and enqueues it to a queue
ConcurrentQueue<int> queue1 = new ConcurrentQueue<int>();
queue1.enqueue(values)
2. To dequeue I use the following Task
public async Task PublishMessage()
{
int waittime =1;
if (waittime != 0)
{
do
{
double[] testarray=new double[512];
if(queue1.Count>=512)
{
wavetest = new double[512];
for (int k = 0; k < 512; k++)
{
queue1.TryDequeue(out testarray[k]);
}
SendMessage(testarray);
}
await Task.Delay(waittime);
}
while (true);
}
}
Thanks
What I have tried:
I tried seeing if the queue increases with time. But no. The queue count was around 250 every. It didn't increase rapidly with time.