473,396 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

NameValueCollection SyncRoot

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.
Nov 17 '05 #1
4 2031
"Steve Long" <St**********@NoSpam.com> wrote in message
news:et**************@TK2MSFTNGP14.phx.gbl...
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
Nov 17 '05 #2
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)
"Alan Pretre" <al********@newsgroup.nospam> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
"Steve Long" <St**********@NoSpam.com> wrote in message
news:et**************@TK2MSFTNGP14.phx.gbl...
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

Nov 17 '05 #3
"Steve Long" <St**********@NoSpam.com> wrote in message
news:OD**************@TK2MSFTNGP14.phx.gbl...
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
Nov 17 '05 #4
Thanks Alan.
"Alan Pretre" <al********@newsgroup.nospam> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
"Steve Long" <St**********@NoSpam.com> wrote in message
news:OD**************@TK2MSFTNGP14.phx.gbl...
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

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Walter Zydhek | last post by:
I am having a problem using the NameValueCollection type. If I remove one of the items while iterating through an collection of this type, I end up with an exception. This exception is:...
2
by: Matt | last post by:
Hello all, I have written a collection class that implements IList. The class currently uses an ArrayList for its internal storage. I am somewhat confused as to how I should implement the...
4
by: chrisben | last post by:
Hi I often use Queue.Synchronized method to create a queue for multithread writing. I also know I could use SyncRoot and lock to write Queue. Could anyone here please explain to me the pros and...
7
by: davidw | last post by:
I always use NameValueCollection. But I read an article says the only differece between Hashtable and NameValueCollection is that NameValueCollection could accept more than one value with same key?...
0
by: Yuri Vanzine | last post by:
Saw this requested awhile ago on Matthew Reynolds's blog here: http://www.dotnet247.com/247reference/msgs/11/57944.aspx Problem: often times I deal with querystring-formatted strings w/o the...
4
by: Kerr | last post by:
Hi all, I've been scouring the internet for help with this problem and every occurance i've seen reconstructs the problem but no one seems to have a solution. Hoping that you guys can help me. ...
5
by: Jacob | last post by:
Hi there, Say I have an ArrayList named list. What's the difference between using lock(list) { .... } and lock(list.SyncRoot) { .... }
2
by: =?Utf-8?B?TWluIFlvbmc=?= | last post by:
I'm not sure if I've just lost it but, I no longer see the property SyncRoot on a Queue. I see that it's a member of the ICollection Base Object, but it's not exposed. Was this intended? Besides...
2
by: eBob.com | last post by:
I was changing some code in a multi-threaded application today and noticed that it was not locking where it really needed to be locking. The Sub was already working with an array so I just stuck a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.