G
Guest
Some classes, like Queue and SortedList, have a Synchronized method which gives a thread safe wrapper object for these classes. But the lock() statement does the same thing. Is there any rules as to when to use one and not the other? For instance, if I wanted to remove an item in a SortedList, would it be better to lock() it or do it via the Synchronized wrapper? Why choose one over the other.
SortedList sl;
lock(sl)
{
sl.Remove(item);
}
OR
SortedList sl2 = SortedList.Synchronized(sl);
sl2.Remove(item);
Same question for iterations. Does lock() and synchronized do the same thing?
lock(sl)
{
for(int i = 0; i < sl.Count; i++)
{
}
}
OR
SortedList sl2 = SortedList.Synchronized(sl);
for(int i = 0; i < sl2.Count; i++)
{
}
Thanks,
Rich Sienkiewicz
Dictaphone Corp
SortedList sl;
lock(sl)
{
sl.Remove(item);
}
OR
SortedList sl2 = SortedList.Synchronized(sl);
sl2.Remove(item);
Same question for iterations. Does lock() and synchronized do the same thing?
lock(sl)
{
for(int i = 0; i < sl.Count; i++)
{
}
}
OR
SortedList sl2 = SortedList.Synchronized(sl);
for(int i = 0; i < sl2.Count; i++)
{
}
Thanks,
Rich Sienkiewicz
Dictaphone Corp