Hashtable.Item thread safety

Hi, I need to know if the Item property of the Hashtable class is thread safe for reading. I just want to be sure because I don't want to introduce the overhead of synching mechanisms unnecessarily. Thanks in advance. Juan.
[230 byte] By [JuanEscalante] at [2007-12-16]
# 1
Unless synchronized with Hashtable.Synchronized() no methods of Hashtable are thread-safe. If multiple threads are accessing the same Hashtable, synchronizing is never "unnecessary overhead".
DanielRieck at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2
Thanks.
Edit: I actually have read the MSDN documentation which says
"To support one or more writers, all operations on the Hashtable must be done through the wrapper returned by the Synchronized method."
My question is: is this necessary when all I'm doing is read?
So I'm wondering, did you assume, from this documentation, that this is the case for reading data from the Hashtable too, or do you know for sure? Or does anyone else know?
JuanEscalante at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 3
I was looking at the disassembly produced by .NET Reflector for the Hashtable class and this is what I found:
The Hashtable.Synchronized method returns a SyncHashtable instance which is a wrapper around the original Hashtable, the getter for the Item property for this wrapper just plain calls the original Hashtable's getter without making any locks, as opposed to the setter which does make a lock on the Hashtable.
So I understand, from this, that reads on the Item property are thread safe, but also that it doesn't hurt, speaking in terms of performance, to use Hashtable.Synchronized, which is probably a good idea if it will be used in a multithreaded application, so you don't need to change that code if you later need that synchronization for whatever reason.
Is all this too obvious?
JuanEscalante at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified