c# - Limit binding updates per second -
i'm creating program reads out data sent via com port , plots live in diagram. data displayed using mvvm principle, works fine when data sent @ around 10hz. however, device data being read can go refresh rate of 1 khz, means 1000 datasets per minute. works fine displaying , updating simple textboxes, breaks diagram because updating happening fast.
what think need limit amount of update events sent subscribed classes , pages, limited amount of data sent through, gives diagram chance draw properly. is there way limit automatically, or code adjustments suggest manually?
a small code snippet collection changed event:
void dataitems_collectionchanged(object sender, system.collections.specialized.notifycollectionchangedeventargs e) { notifypropertychanged("dataitems"); notifypropertychanged("lastitem"); // update charts notifypropertychanged("accelxdata"); notifypropertychanged("accelydata"); notifypropertychanged("accelzdata"); } // handle property changes public event propertychangedeventhandler propertychanged; private void notifypropertychanged(string propertyname) { var handler = this.propertychanged; if (handler != null) handler(this, new propertychangedeventargs(propertyname)); }
every dataset has id maybe can used check when update manually, idea.
a better approach remove calls notifypropertychanged whenever data changes.
create timer , refresh on timer. way can control refresh rate, , not bound rate @ data arrives.
Comments
Post a Comment