Synchronize mthd

G

Guest

I'm trying to figure out how to implement a static Synchronized() method
(like those supported in many of the classes in the Collections namespace).

I'm deriving from CollectionBase for a strongly typed collection. I think I
understand how to use the SyncRoot property to safeguard operations:

lock(this.SyncRoot)
{
// do the operation... add or remove or whatever
}


When I run Object.ReferenceEquals(o1, o2)
//where
o1 = new ArrayList();
// and
02 = ArrayList.Synchronized(o1);

I get false. So there's an entirely new arraylist object created,
presumably with an internal flag saying do only synchronized operations. But
they must share the same internal data structure.

So when I implement Synchronized(o), do I do this....

1. Create a new instance of the CollectionBase-derived class.
2. Set a bool flag saying do only thread-safe operations
3. Copy the IList from the 'o' passed in to the new CollectionBase-derived
class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top