Hi Dave,
Yes, from the doc we will know that when multiple threads may read/write to
the HashTable in the same time, we need to do thread synchronization.
Thread Safety
Hashtable is thread safe for use by multiple reader threads, or a single
writing thread. It is not thread safe for multi-thread use, when any of the
threads perform write (update) operations. To support multiple writers all
operations on the Hashtable must be done through the wrapper returned by
the Synchronized method, provided that there are no threads reading the
Hashtable object.
Enumerating through a collection is intrinsically not a thread safe
procedure. Even when a collection is synchronized, other threads can still
modify the collection, which causes the enumerator to throw an exception.
To guarantee thread safety during enumeration, you can either lock the
collection during the entire enumeration or catch the exceptions resulting
from changes made by other threads.
Hashtable Class
http://msdn2.microsoft.com/en-us/library/system.collections.hashtable.aspx Hashtable.Synchronized Method
http://msdn2.microsoft.com/en-us/library/system.collections.hashtable.synchr onized.aspx
In addition to the lock method, we have other approach thread
synchronization approach, but I think this one is easier.
e.g. ReaderWriterLock, AutoResetEvent and so on.
The goal to do thread synchronization is to prevent the scenario that
multiple threads access to a not thread safe object in the same time. In
this scenario, no writer thread and read thread access to the HashTable in
the same time.
Best regards,
Perter Huang
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights.