T
tamara.roberson
I am porting some code to use generics. Currently, we have a
synchronized Hashtable called as follows:
private Hashtable table = Hashtable.Synchronized (new Hashtable ());
What I would like to do is to port this to a Dictionary so that it can
be type-safe:
private Dictionary<string,string> table = new Dictionary<string,string>
();
But this loses our synchronization. I was suprised to find that there
is no built-in method for an automatically synchronized Dictionary. So
what should I do?
Some options:
* add 'volatile' keyword to declaration
* wrap all modifications of the table with lock(table) { ... }
* use some other locking mechanism
* stick to using Hashtable for now, threading hurts my my head and its
better to just leave it alone and not break the whole thing
Thanks!
Tamara
synchronized Hashtable called as follows:
private Hashtable table = Hashtable.Synchronized (new Hashtable ());
What I would like to do is to port this to a Dictionary so that it can
be type-safe:
private Dictionary<string,string> table = new Dictionary<string,string>
();
But this loses our synchronization. I was suprised to find that there
is no built-in method for an automatically synchronized Dictionary. So
what should I do?
Some options:
* add 'volatile' keyword to declaration
* wrap all modifications of the table with lock(table) { ... }
* use some other locking mechanism
* stick to using Hashtable for now, threading hurts my my head and its
better to just leave it alone and not break the whole thing

Thanks!
Tamara