Or should you always create some other lock object?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With