Click here to Skip to main content
15,907,910 members

Comments by Member 13245297 (Top 4 by date)

Member 13245297 1-May-18 13:31pm View    
Hi. Thanks for pointing that mistake. I will rectify it. I couldn't understand the second point properly. Right now,I am actually starting the task PubMessage when my program begins execution and it will check whether the condition(Count>512) is met every milli second and if the condition is met it will send the message. So my main program will enqueue all the data points received every milli-second and the task PubMessage will periodically dequeue the contents and send it. You have any suggestion to optimize my solution? Thanks
Member 13245297 1-May-18 13:11pm View    
Hi. Thanks for pointing that mistake out. What if I maintain a queue and enqueues it with the message read and have a task which will periodically dequeue the contents and process it? It will make sure that I wont miss any data, right? Thanks
Member 13245297 1-May-18 7:21am View    
Thanks for replying
Member 13245297 1-May-18 7:21am View    
I do the following:
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 PubMessage()
{
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);
}

}