Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Under what cirumstances does ConcurrentDictionary.TryRemove() return false? [duplicate]

I've been searching for a way to remove an item from a concurrent dictionary. For some reason there's no Remove method, but there's a TryRemove method, that returns a bool. In MSDN it's said that false is returned in case the process "failed", but doesn't say in what way.

  1. Is it false when the element is absent only?
  2. Is it false when the element couldn't be removed due to a lock?
like image 699
polkovnikov.ph Avatar asked Sep 15 '25 06:09

polkovnikov.ph


1 Answers

1st option only: when there's no key to remove; locking is ConcurrentDictionary internal implementation and it should not be visible from outside.

According to comment by Dmitry Bychenko.

like image 134
flindeberg Avatar answered Sep 17 '25 18:09

flindeberg