Use TryAdd(data)
Method. You can also pass in a timespan
object or and int
indicating a timeout period. Returns true
or false
.
Note that if the underlying collection type cannot handle duplicates and the data you are trying to add IS a duplicate then an InvalidOperationException
is raised.