C# Programming
12-03-2009, 06:52 AM
I’ve using a Queue to store data and I do polling in order to know if the Queue contain data ( that I understand is not the correct approach)
For Example
private void PopDataFromQueue()
{
bool isRspOK;
byte [] data;
while (true)
{
//If so then stop the thread
if (m_isStopReadingQueueThread == true)
break;
if (m_queue.Count > 0)
{
lock (m_queue)
{
if (m_queue.Count > 0)
{
data = (byte [])m_queue.Dequeue();
isRspOK = m_scenario.Parse(sockBuf.SocketData);
if (isRspOK == true)
{
;
}
}
}
}
}
I need to implement approach that wait for event occur and not always check the Queue status
The function PopDataFromQueue is define as a thread
Something like this
private void PopDataFromQueue()
{
//create timer event that indicate in case the event that I waiting for not reach after some time , need to handle it
Timer timer = new timer(1000);
while (true)
{
//If so then stop the thread
if (m_isStopReadingQueueThread == true)
break;
Event = WaitForEvent(Queue.Add,Timer. expire); // need to wait for two type of events
Switch(Event)
{
case Queue.Dataexist:
data = (byte [])m_queue.Dequeue();
isRspOK = m_scenario.Parse(sockBuf.SocketData);
if (isRspOK == true)
{
;
}
Break;
Case timer.expire:
isStopReadingQueueThread =true;
break;
}
}
}
I try to look in the net and I didn’t found
Any advice?
Thanks
Ronen
For Example
private void PopDataFromQueue()
{
bool isRspOK;
byte [] data;
while (true)
{
//If so then stop the thread
if (m_isStopReadingQueueThread == true)
break;
if (m_queue.Count > 0)
{
lock (m_queue)
{
if (m_queue.Count > 0)
{
data = (byte [])m_queue.Dequeue();
isRspOK = m_scenario.Parse(sockBuf.SocketData);
if (isRspOK == true)
{
;
}
}
}
}
}
I need to implement approach that wait for event occur and not always check the Queue status
The function PopDataFromQueue is define as a thread
Something like this
private void PopDataFromQueue()
{
//create timer event that indicate in case the event that I waiting for not reach after some time , need to handle it
Timer timer = new timer(1000);
while (true)
{
//If so then stop the thread
if (m_isStopReadingQueueThread == true)
break;
Event = WaitForEvent(Queue.Add,Timer. expire); // need to wait for two type of events
Switch(Event)
{
case Queue.Dataexist:
data = (byte [])m_queue.Dequeue();
isRspOK = m_scenario.Parse(sockBuf.SocketData);
if (isRspOK == true)
{
;
}
Break;
Case timer.expire:
isStopReadingQueueThread =true;
break;
}
}
}
I try to look in the net and I didn’t found
Any advice?
Thanks
Ronen