I understood the fact and tried to write a wrapper over this class and make a generic thread safe dictionary for using it in my application.
So what i did in this wrapper is i maintained a reference to the generic dictionary and implemented IDictionary
However while discussing it with one of the colleagues i realize that still is not really a thread safe class. It can still cause problem when i am trying to use IEnumerator. Let's see how
when we loop through a dict with 3 elements with SynchronizedDictionary
foreach(KeyValue
will perform like
lock
get enumerator
unlock
<--- another thread might modify as dict is not locked now
lock (assuming returned enumerator calls this[TKey key] for fetching items. else it won't be even locked!)
get first item
unlock
<--- another thread might modify as dict is not locked now
lock
get second item
unlock
<--- another thread might modify as dict is not locked now
lock
get third item
unlock
and hence there's a problem.
Any suggestions out there so resolve this problem.
~Abhishek