ConcurrentQueue(Of T)
The ConcurrentQueue(Of T)
collection is just a thread-safe implementation of the Queue(Of T)
collection; therefore, 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:
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 returns True
in cases of success, otherwise False
. Still the Count
property returns the number of items in the queue.
Get Visual Basic® 2010 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.