Hashtables have a syncroot property but generic dictionaries don’t. If I have code that does this:
lock (hashtable.Syncroot) { .... }
How do I replicate this if I am removing the hashtable and changing to generic dictionaries?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you are going strictly for compatability then Bryan is correct. This is the best way to maintain your current semantics on top of a Dictionary.
Expanding on it though. The reason the SyncRoot property was not directly added to the generic dictionary is that it’s a dangerous way to do synchronization. It’s only slighly better than ‘lock(this)’ which is very dangerous and prone to deadlocks. Here are a couple of links that speak to why this is bad.