Hashtable to Dictionary<> syncroot .

前端 未结 4 1179
闹比i
闹比i 2020-12-03 14:45

Hashtables have a syncroot property but generic dictionaries don\'t. If I have code that does this:

lock (hashtable.Syncroot)
{
....
}

How

4条回答
  •  孤街浪徒
    2020-12-03 15:46

    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.

    • http://blogs.msdn.com/bclteam/archive/2005/03/15/396399.aspx
    • http://blogs.msdn.com/ricom/archive/2006/05/01/587750.aspx

提交回复
热议问题