Z
Zach
The code below was taken from an MSDN example.
The example contains explantory lines. Nevertheless
I do not understand the use of the while loop. Because
of the Pulse within the loop, I would expect the loop
to end after the dequeue. If that is correct this would
be one off situation, I therefore don't understand why
a loop was used.
There are two threads in the example.
public void SecondThread()
{
lock(m_smplQueue)
{
Monitor.Pulse(m_smplQueue);
while(Monitor.Wait(m_smplQueue,1000))
{
int counter = (int)m_smplQueue.Dequeue();
Console.WriteLine(counter.ToString());
Monitor.Pulse(m_smplQueue);
}
}
}
The example contains explantory lines. Nevertheless
I do not understand the use of the while loop. Because
of the Pulse within the loop, I would expect the loop
to end after the dequeue. If that is correct this would
be one off situation, I therefore don't understand why
a loop was used.
There are two threads in the example.
public void SecondThread()
{
lock(m_smplQueue)
{
Monitor.Pulse(m_smplQueue);
while(Monitor.Wait(m_smplQueue,1000))
{
int counter = (int)m_smplQueue.Dequeue();
Console.WriteLine(counter.ToString());
Monitor.Pulse(m_smplQueue);
}
}
}