or should you always create some other lock object . .
+4
A:
Yes, cast it to an IDictionary and lock on .SyncRoot
:
Generic.Dictionary<int, int> dic = new Generic.Dictionary<int, int>();
lock (((IDictionary)dic).SyncRoot)
{
// code
}
Thanks to this source for the info.
Of course a thread-safe dictionary would be nice, too, as others have suggested.
Michael Haren
2009-01-04 01:54:43
+1
A:
Hi,
You should take a look at the Thread Safe Dictionary Implementation made by Brian Rudolph which is nativly Thread Safe.
http://devplanet.com/blogs/brianr/archive/2008/09/26/thread-safe-dictionary-in-net.aspx
Yoann. B
2009-01-04 01:55:00
+1
A:
You can lock on any object that you wish (except value-types). It's recommended though to lock on the .SyncRoot object.
Vilx-
2009-01-04 01:55:42
A:
Check this question.
Also check this question:
What’s the best way of implementing a thread-safe Dictionary in .NET?
CMS
2009-01-04 02:07:57