NameValueCollection SyncRoot

  • Thread starter Thread starter Steve Long
  • Start date Start date
S

Steve Long

Can anybody help me out with a code sample or other info on how to implement
SyncRoot on a NameValueCollection? Or, is there another .NET class that does
this for me with the same functionality as a NameValueCollection? Basically,
I need mulitple value for any given key and I need to try and make sure it's
tread safe. I can derive from it but it doesn't implement the SyncRoot
member of the NameObjectCollectionBase.

Thanks in advance
Steve
P.S. I hope this isn't just too simple. Sorry if it is.
 
Steve Long said:
Can anybody help me out with a code sample or other info on how to
implement
SyncRoot on a NameValueCollection? Or, is there another .NET class that
does
this for me with the same functionality as a NameValueCollection?
Basically,
I need mulitple value for any given key and I need to try and make sure
it's
tread safe. I can derive from it but it doesn't implement the SyncRoot
member of the NameObjectCollectionBase.

Hi. How about this:

System.Collections.Specialized.NameValueCollection x = new
System.Collections.Specialized.NameValueCollection();

lock (((System.Collections.ICollection) x).SyncRoot) {
}

-- Alan
 
So, if I implement ICollection in my class, just put this code in the
SyncRoot property of that implementation with x being (this)?

Steve (still a little confused)
 
Steve Long said:
So, if I implement ICollection in my class, just put this code in the
SyncRoot property of that implementation with x being (this)?

The documentation shows that it implements ICollection, so SyncRoot should
be there for you already. Just cast your NameValueCollection object to an
ICollection when you want access to SyncRoot.

[Serializable]
public abstract class NameObjectCollectionBase : ICollection, IEnumerable,
ISerializable, IDeserializationCallback

-- Alan
 
Thanks Alan.


Alan Pretre said:
Steve Long said:
So, if I implement ICollection in my class, just put this code in the
SyncRoot property of that implementation with x being (this)?

The documentation shows that it implements ICollection, so SyncRoot should
be there for you already. Just cast your NameValueCollection object to an
ICollection when you want access to SyncRoot.

[Serializable]
public abstract class NameObjectCollectionBase : ICollection, IEnumerable,
ISerializable, IDeserializationCallback

-- Alan
 
Back
Top