I want to create a synchronised queue class which has very simple
functionality as a queue but is thread safe, where two different threads can
add and remove items in such a way that doesn't interfere with each other.

Will the following code suffice. Does the synchronised method return a queue
that can only be accessed by a single thread at any one time.

Also what happens if you try and remove (dequeue) an item when the queue is
empty. Will the thread be blocked until a new item is added to the queue.

Effectively what I am trying to do, is a single producer - single consumer
solution (which fits the requirements fine) without getting into all the
complexities related to ReaderWriter locks etc.


TIA

Jason

Public Class MyMessageQueue

Dim synchQueue As Queue = Queue.Synchronized(New Queue)

Public Sub Add(ByVal strMessage As String)
synchQueue.Enqueue(strMessage)
End Sub

Public Function Remove() As String
Return synchQueue.Dequeue
End Function

Public Function Count() As Long
Return synchQueue.Count
End Function

End Class