I believe the biggest reason is that setting up a parallel queue (where two or more threads always control the content) to count elements is an incorrect concept to start with. I suspect that they only provided the Count property for existing interfaces. Therefore, if the only reason api exists is to satisfy the requirements for the interface, then who cares about how it works, since you should not use it for a start.
When working with objects that are modified by several threads, you should never ask the object about any state / value that another thread can change. Because by the time you answer your question, it can no longer be the correct answer. This seems to be the main problem in the WinForm "InvokeRequired" property. Some APIs are just a bad idea in a multi-threaded environment, and I think this graph falls into this category.
Ultimately, it is strange that the developers did not use an explicit member of the interface for the ICollection.Count property, but did not publish it. Then at least you know that you should not use it. They pointed to the use of IsEmpty on MSDN; however, it is easy to miss it.
csharptest.net
source share