Event is fired multiple times

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

    #1

    Event is fired multiple times

    Hello Everyone,

    I am having an issue where an event appears to be fired repeatedly where I
    only expect it to be fired once. See below for objects and behaviors.

    I have a control that contains a treeview, it creates the TopLevel object
    and subscribes to the ObjectChanged Event. When the event is fired, I
    rebuild the treeview. If I change data from TopLevelData, the event is
    fired just once. When I change data in ChildObject, the event is fired
    multiple times. Perhaps the Event doesn't know it was heard and feels the
    need to repeat itself.

    I am sure I am missing something, anyone have any ideas what that is?

    VB2005, WinXP

    Here is a sample of what I am doing.

    Class TopLevel

    Readonly Property TopLevelData
    Readonly Property ChildCollection

    OnEvent ChildCollection .ListChanged, RaiseEvent ObjectChanged
    OnEvent TopLevelData.Pr opertyChanged, RaiseEvent ObjectChanged

    Class TopLevelData

    On Property Change, RaiseEvent PropertyChanged

    Class ChildCollection (ListOf ChildObject)

    On Event ChildObject Property Change, RaiseEvent ListChanged
    On Addition or Deletion of ChildObject, RaiseEvent ListChanged

    Class ChildObject

    On Property Change, RaiseEvent PropertyChanged



  • Matt F

    #2
    Re: Event is fired multiple times

    Random guess since I don't work with treeviews much:

    Child object changes - fires event
    Top Level object recognizes change of one of it's children, hence a change
    to something in it's heiarchy, - fires event.

    test: comment out "OnEvent TopLevelData.Pr opertyChanged, RaiseEvent
    ObjectChanged" and modify child object - if only fires once, it give a
    pretty good idea




    "AMDRIT" <amdrit@hotmail .comwrote in message
    news:uEN012ZNHH A.4604@TK2MSFTN GP06.phx.gbl...
    Hello Everyone,
    >
    I am having an issue where an event appears to be fired repeatedly where I
    only expect it to be fired once. See below for objects and behaviors.
    >
    I have a control that contains a treeview, it creates the TopLevel object
    and subscribes to the ObjectChanged Event. When the event is fired, I
    rebuild the treeview. If I change data from TopLevelData, the event is
    fired just once. When I change data in ChildObject, the event is fired
    multiple times. Perhaps the Event doesn't know it was heard and feels the
    need to repeat itself.
    >
    I am sure I am missing something, anyone have any ideas what that is?
    >
    VB2005, WinXP
    >
    Here is a sample of what I am doing.
    >
    Class TopLevel
    >
    Readonly Property TopLevelData
    Readonly Property ChildCollection
    >
    OnEvent ChildCollection .ListChanged, RaiseEvent ObjectChanged
    OnEvent TopLevelData.Pr opertyChanged, RaiseEvent ObjectChanged
    >
    Class TopLevelData
    >
    On Property Change, RaiseEvent PropertyChanged
    >
    Class ChildCollection (ListOf ChildObject)
    >
    On Event ChildObject Property Change, RaiseEvent ListChanged
    On Addition or Deletion of ChildObject, RaiseEvent ListChanged
    >
    Class ChildObject
    >
    On Property Change, RaiseEvent PropertyChanged
    >
    >
    >

    Comment

    • AMDRIT

      #3
      Re: Event is fired multiple times

      Thanks for the reply.

      I thought of these too, and am still perplexed.

      Here is my logic for property set

      Dim strTemp As String = pstrInstanceNam e

      If String.Compare( value, strTemp, False) <0 Then
      pstrInstanceNam e = value
      Trace.WriteLine (String.Format( "Property:{ 0} changed",
      "InstanceName") )
      RaiseEvent PropertyChanged (Me, New
      PropertyChanged EventArgs("Inst anceName", strTemp, pstrInstanceNam e))
      End If

      Below is trace log output. I have three actions: Create the TopLevel,
      Create a ChildObject, Change a ChildObject property value.

      Creating and instantiating the TopLevel Class
      ----------------------------------------------
      Property:Projec tName changed
      S T A R T B I N D I N G T R E E
      E N D B I N D I N G T R E E

      Creating a new BusinessObject object
      -------------------------------------
      Property:Busine ssObjects changed
      List:ProjectInf os changed
      S T A R T B I N D I N G T R E E
      E N D B I N D I N G T R E E
      Property:Busine ssObjects changed
      List:ProjectInf os changed
      S T A R T B I N D I N G T R E E
      E N D B I N D I N G T R E E
      Property:Busine ssObjects changed
      List:ProjectInf os changed
      S T A R T B I N D I N G T R E E
      E N D B I N D I N G T R E E

      Changing a property value in BusinessObject
      -------------------------------------------
      Property:Instan ceName changed
      Property:Busine ssObjects changed
      List:ProjectInf os changed
      S T A R T B I N D I N G T R E E
      E N D B I N D I N G T R E E
      Property:Busine ssObjects changed
      List:ProjectInf os changed
      S T A R T B I N D I N G T R E E
      E N D B I N D I N G T R E E
      Property:Busine ssObjects changed
      List:ProjectInf os changed
      S T A R T B I N D I N G T R E E
      E N D B I N D I N G T R E E
      Property:Busine ssObjects changed
      List:ProjectInf os changed
      S T A R T B I N D I N G T R E E
      E N D B I N D I N G T R E E
      Property:Busine ssObjects changed
      List:ProjectInf os changed
      S T A R T B I N D I N G T R E E
      E N D B I N D I N G T R E E
      Property:Busine ssObjects changed
      List:ProjectInf os changed
      S T A R T B I N D I N G T R E E
      E N D B I N D I N G T R E E
      Property:Busine ssObjects changed
      List:ProjectInf os changed
      S T A R T B I N D I N G T R E E
      E N D B I N D I N G T R E E


      "Matt F" <mfielderREMOVE CAPS@nospam.nos pamwrote in message
      news:%23KySqtaN HHA.4244@TK2MSF TNGP04.phx.gbl. ..
      Random guess since I don't work with treeviews much:
      >
      Child object changes - fires event
      Top Level object recognizes change of one of it's children, hence a change
      to something in it's heiarchy, - fires event.
      >
      test: comment out "OnEvent TopLevelData.Pr opertyChanged, RaiseEvent
      ObjectChanged" and modify child object - if only fires once, it give a
      pretty good idea
      >
      >
      >
      >
      "AMDRIT" <amdrit@hotmail .comwrote in message
      news:uEN012ZNHH A.4604@TK2MSFTN GP06.phx.gbl...
      >Hello Everyone,
      >>
      >I am having an issue where an event appears to be fired repeatedly where
      >I only expect it to be fired once. See below for objects and behaviors.
      >>
      >I have a control that contains a treeview, it creates the TopLevel object
      >and subscribes to the ObjectChanged Event. When the event is fired, I
      >rebuild the treeview. If I change data from TopLevelData, the event is
      >fired just once. When I change data in ChildObject, the event is fired
      >multiple times. Perhaps the Event doesn't know it was heard and feels
      >the need to repeat itself.
      >>
      >I am sure I am missing something, anyone have any ideas what that is?
      >>
      >VB2005, WinXP
      >>
      >Here is a sample of what I am doing.
      >>
      >Class TopLevel
      >>
      > Readonly Property TopLevelData
      > Readonly Property ChildCollection
      >>
      > OnEvent ChildCollection .ListChanged, RaiseEvent ObjectChanged
      > OnEvent TopLevelData.Pr opertyChanged, RaiseEvent ObjectChanged
      >>
      >Class TopLevelData
      >>
      > On Property Change, RaiseEvent PropertyChanged
      >>
      >Class ChildCollection (ListOf ChildObject)
      >>
      > On Event ChildObject Property Change, RaiseEvent ListChanged
      > On Addition or Deletion of ChildObject, RaiseEvent ListChanged
      >>
      >Class ChildObject
      >>
      > On Property Change, RaiseEvent PropertyChanged
      >>
      >>
      >>
      >
      >

      Comment

      Working...