H
Hans Olav Stjernholm
Hi!
I'm using C# and have done a bit of reading about the synchronization
mechanisms in .Net.
My understanding is that a lock on an instance object makes sure that no
other threads can access the object while locked.
lock (myObj)
{
}
I have my own collection and use lock inside the Remove and Add methods. My
question is this: Is it thread safe to enumerate through the collection
without a lock the collection?
foreach (object obj in myCollection)
{
}
Or do I have to suffer a lock on the object here also?
Any answers and elaborations are really welcomed!!!
Regards,
Hans Olav.
I'm using C# and have done a bit of reading about the synchronization
mechanisms in .Net.
My understanding is that a lock on an instance object makes sure that no
other threads can access the object while locked.
lock (myObj)
{
}
I have my own collection and use lock inside the Remove and Add methods. My
question is this: Is it thread safe to enumerate through the collection
without a lock the collection?
foreach (object obj in myCollection)
{
}
Or do I have to suffer a lock on the object here also?
Any answers and elaborations are really welcomed!!!
Regards,
Hans Olav.