Event is fired multiple times

A

AMDRIT

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.PropertyChanged, 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
 
M

Matt F

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.PropertyChanged, RaiseEvent
ObjectChanged" and modify child object - if only fires once, it give a
pretty good idea
 
A

AMDRIT

Thanks for the reply.

I thought of these too, and am still perplexed.

Here is my logic for property set

Dim strTemp As String = pstrInstanceName

If String.Compare(value, strTemp, False) <> 0 Then
pstrInstanceName = value
Trace.WriteLine(String.Format("Property:{0} changed",
"InstanceName"))
RaiseEvent PropertyChanged(Me, New
PropertyChangedEventArgs("InstanceName", strTemp, pstrInstanceName))
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:projectName 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:BusinessObjects changed
List:projectInfos 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:BusinessObjects changed
List:projectInfos 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:BusinessObjects changed
List:projectInfos 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:InstanceName changed
Property:BusinessObjects changed
List:projectInfos 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:BusinessObjects changed
List:projectInfos 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:BusinessObjects changed
List:projectInfos 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:BusinessObjects changed
List:projectInfos 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:BusinessObjects changed
List:projectInfos 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:BusinessObjects changed
List:projectInfos 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:BusinessObjects changed
List:projectInfos 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
 

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