ConcurrentQueue(Of T)

The ConcurrentQueue(Of T) collection is just a thread-safe implementation of the Queue(Of T) collection, so it takes the logic of FIFO (first in, first out), where the first element in the collection is the first to be removed. The following code shows an example:

'Creating an instanceDim cq As New ConcurrentQueue(Of Integer)'Adding itemscq.Enqueue(1)cq.Enqueue(2)'Removing an item from the queueDim item As Integercq.TryDequeue(item)Console.WriteLine(item)'Returns "1":Console.WriteLine(cq.Count)

The main difference with Queue is how items are removed from the queue. In this concurrent implementation, you invoke TryDequeue, which passes the removed item to a result variable by reference. The method ...

Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.