NameValueCollection SyncRoot

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Long

    NameValueCollection SyncRoot

    Can anybody help me out with a code sample or other info on how to implement
    SyncRoot on a NameValueCollec tion? Or, is there another .NET class that does
    this for me with the same functionality as a NameValueCollec tion? 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 NameObjectColle ctionBase.

    Thanks in advance
    Steve
    P.S. I hope this isn't just too simple. Sorry if it is.


  • Alan Pretre

    #2
    Re: NameValueCollec tion SyncRoot

    "Steve Long" <Steve_Noneya@N oSpam.com> wrote in message
    news:etZOzhwVFH A.1452@TK2MSFTN GP14.phx.gbl...[color=blue]
    > Can anybody help me out with a code sample or other info on how to
    > implement
    > SyncRoot on a NameValueCollec tion? Or, is there another .NET class that
    > does
    > this for me with the same functionality as a NameValueCollec tion?
    > 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 NameObjectColle ctionBase.[/color]

    Hi. How about this:

    System.Collecti ons.Specialized .NameValueColle ction x = new
    System.Collecti ons.Specialized .NameValueColle ction();

    lock (((System.Colle ctions.ICollect ion) x).SyncRoot) {
    }

    -- Alan


    Comment

    • Steve Long

      #3
      Re: NameValueCollec tion SyncRoot

      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" <alanpretre@new sgroup.nospam> wrote in message
      news:%23fwZlwxV FHA.228@TK2MSFT NGP12.phx.gbl.. .[color=blue]
      > "Steve Long" <Steve_Noneya@N oSpam.com> wrote in message
      > news:etZOzhwVFH A.1452@TK2MSFTN GP14.phx.gbl...[color=green]
      > > Can anybody help me out with a code sample or other info on how to
      > > implement
      > > SyncRoot on a NameValueCollec tion? Or, is there another .NET class that
      > > does
      > > this for me with the same functionality as a NameValueCollec tion?
      > > 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 NameObjectColle ctionBase.[/color]
      >
      > Hi. How about this:
      >
      > System.Collecti ons.Specialized .NameValueColle ction x = new
      > System.Collecti ons.Specialized .NameValueColle ction();
      >
      > lock (((System.Colle ctions.ICollect ion) x).SyncRoot) {
      > }
      >
      > -- Alan
      >
      >[/color]


      Comment

      • Alan Pretre

        #4
        Re: NameValueCollec tion SyncRoot

        "Steve Long" <Steve_Noneya@N oSpam.com> wrote in message
        news:ODXaR5xVFH A.2616@TK2MSFTN GP14.phx.gbl...[color=blue]
        > So, if I implement ICollection in my class, just put this code in the
        > SyncRoot property of that implementation with x being (this)?[/color]

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

        [Serializable]
        public abstract class NameObjectColle ctionBase : ICollection, IEnumerable,
        ISerializable, IDeserializatio nCallback

        -- Alan


        Comment

        • Steve Long

          #5
          Re: NameValueCollec tion SyncRoot

          Thanks Alan.


          "Alan Pretre" <alanpretre@new sgroup.nospam> wrote in message
          news:%23UPkgQyV FHA.3184@TK2MSF TNGP15.phx.gbl. ..[color=blue]
          > "Steve Long" <Steve_Noneya@N oSpam.com> wrote in message
          > news:ODXaR5xVFH A.2616@TK2MSFTN GP14.phx.gbl...[color=green]
          > > So, if I implement ICollection in my class, just put this code in the
          > > SyncRoot property of that implementation with x being (this)?[/color]
          >
          > The documentation shows that it implements ICollection, so SyncRoot should
          > be there for you already. Just cast your NameValueCollec tion object to an
          > ICollection when you want access to SyncRoot.
          >
          > [Serializable]
          > public abstract class NameObjectColle ctionBase : ICollection, IEnumerable,
          > ISerializable, IDeserializatio nCallback
          >
          > -- Alan
          >
          >[/color]


          Comment

          Working...