ConcurrentBag(T) Class eepresents a thread-safe, unordered collection of objects.
Imports System.Collections.Concurrent
Module ConcurrentBagDemo
Sub Main()
Dim cb As New ConcurrentBag(Of Integer)()
cb.Add(1)
cb.Add(2)
cb.Add(3)
Dim item As Integer
While Not cb.IsEmpty
If cb.TryTake(item) Then
Console.WriteLine(item)
Else
Console.WriteLine("TryTake failed for non-empty bag")
End If
End While
If cb.TryPeek(item) Then
Console.WriteLine("TryPeek succeeded for empty bag!")
End If
End Sub
End Module
Related examples in the same category