G
Guest
Hi all,
I got a question here which about using queue. i have create a class of queue.
Public Sub Add(ByVal data As Object)
SyncLock Me
_Data.Enqueue(data)
Monitor.Pulse(Me)
End SyncLock
End Sub
Public Function GetNext() As Object
SyncLock Me
While _Data.Count = 0
Monitor.Wait(Me)
End While
Return _Data.Dequeue()
End SyncLock
End Function
above are part of the class of queue. I am going to start a thread to add data to the queue. At the same time, another thread are also start to get data.
if the queue is empty, the thread will wait until the other thread (add) add data into queue.
My problem is if there is no more data to add into queue, the thread (get) is still waiting. I would like to ask how can I add WaitForCompletion to handle it.
I got a question here which about using queue. i have create a class of queue.
Public Sub Add(ByVal data As Object)
SyncLock Me
_Data.Enqueue(data)
Monitor.Pulse(Me)
End SyncLock
End Sub
Public Function GetNext() As Object
SyncLock Me
While _Data.Count = 0
Monitor.Wait(Me)
End While
Return _Data.Dequeue()
End SyncLock
End Function
above are part of the class of queue. I am going to start a thread to add data to the queue. At the same time, another thread are also start to get data.
if the queue is empty, the thread will wait until the other thread (add) add data into queue.
My problem is if there is no more data to add into queue, the thread (get) is still waiting. I would like to ask how can I add WaitForCompletion to handle it.