Print Page | Close Window

Disable Collection Change Notifications

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=4018
Printed Date: 12-May-2026 at 9:34pm


Topic: Disable Collection Change Notifications
Posted By: chuckc
Subject: Disable Collection Change Notifications
Date Posted: 05-Mar-2013 at 12:54pm
I have a RelatedEntityList bound to a grid.  When the user adds a large number of items to the RelatedEntityList using the Add method, I see a lot of notifications that degrade UI performance. 

What is a good way to disable or minimize these notificatons?  The RelatedEntityList doesn't appear to have an AddRange method, which would probably help minimize notifications.  Can I temporarily turn off notifications from RelatedEntityList?  Or at the EntityManager?

Thanks for your help.



Replies:
Posted By: sbelini
Date Posted: 06-Mar-2013 at 11:48am
Hi chuckc,

Unfortunately, it's not possible to disable RelatedEntityList CollectionChanged event.

I'm creating a feature request for an AddRange method.

sbelini


Posted By: stephenmcd1
Date Posted: 13-Mar-2013 at 11:51am
This might not be directly related to your problem but I thought I'd mention it here for completeness.  I also just happened to be looking at this kind of thing so it's fresh in my mind. 

It is possible to disable these notifications.  The following code will add 10 child "OrderDetail" rows to a RelatedEntityList without raising any change notifications:
//The 'parent' entity
var order = new Order();

//Disable change notifications on the parent entity's group (maybe check if it is already
//  disabled so you don't mess with the existing state?)
order.EntityAspect.EntityGroup.ChangeNotificationEnabled = false;

//Get the RelatedEntityList
RelatedEntityList<OrderDetail> entityList = order.OrderDetails;

//Add 10 detail rows - none of these will trigger a CollectionChanged event
for (var i = 0; i < 10;i++ )
    entityList.Add(new OrderDetail());

//Re-enable notifications for future operations
order.EntityAspect.EntityGroup.ChangeNotificationEnabled = true;

However, I'm not sure that this would actually help you out if your UI is bound to the related entity list.  You basically would have added 10 items behind its back.....so they wouldn't show up.  Perhaps you could somehow force the UI to 'refresh' itself after you did the bulk loading.  Or you may just need to wait until an AddRange() method gets added.

You can read more about EntityGroup.ChangeNotificationsEnabled on the http://drc.ideablade.com/devforce-2012/bin/view/Documentation/entity-events#HEntityGroupevents - Listen for Changes wiki page.  I'll specifically quote this note/warning:

There may be cases where a developer wants to suppress all "change notification" within an EntityGroup for a period of time.  This can be accomplished by setting the ChangeNotificationEnabled property to 'false'. Note that this will effect change notification at the EntityManager level (EntityChanging, EntityChanged) as well as at the Entity level (INotifyPropertyChanged).



Print Page | Close Window