Static dictionary in .Net Thread safety
Posted
by
Emmanuel
on Stack Overflow
See other posts from Stack Overflow
or by Emmanuel
Published on 2009-04-29T20:21:54Z
Indexed on
2011/01/06
20:54 UTC
Read the original article
Hit count: 178
Reading msdn documentation for dictionaries it says : "Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe."
Those this mean that with a dictionary such as this :
static object syncObject = new object();
static Dictionary<string,MyObject> mydictionary= new Dictionary<string, MyObject>();
Is doing something like the code below unnecessary?
lock (syncObject)
{
context = new TDataContext();
mydictionary.Add("key", myObject);
}
© Stack Overflow or respective owner