限制每秒绑定更新 [英] Limit binding updates per second

查看:48
本文介绍了限制每秒绑定更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在创建一个程序,该程序读取通过 COM 端口发送的数据,然后将其绘制在图表中.数据显示使用 MVVM 原理,当数据以 10Hz 左右发送时,该原理工作正常.但是,正在从中读取数据的设备可以达到 1 kHz 的刷新率,这意味着每分钟 1000 个数据集.这适用于显示和更新简单的文本框,但由于更新速度太快而破坏了图表.

I'm currently creating a program that reads out data sent via a COM port and then plots it live in a diagram. The data is displayed using the MVVM principle, which works fine when data is sent at around 10Hz. However, the device the data is being read from can go up to a refresh rate of 1 kHz, which means 1000 datasets per minute. This works fine for displaying and updating simple textboxes, however it breaks the diagram because the updating is happening too fast.

我认为我现在需要做的是限制发送到订阅类和页面的更新事件的数量,以便只发送有限数量的数据,这使图表有机会正确绘制.有没有办法自动限制这种情况,或者您建议手动调整哪些代码?

What I think I need to do now is limit the amount of update events that is sent to the subscribed classes and pages, so that only a limited amount of data is sent through, which gives the diagram a chance to draw properly. Is there a way to limit this automatically, or what code adjustments would you suggest to do just that manually?

我收藏中的一小段代码改变了事件:

A small code snippet from my collection changed event:

void dataItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
    NotifyPropertyChanged("dataItems");
    NotifyPropertyChanged("lastItem");

    // update any 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));
}

每个数据集也有一个 ID,也许可以用来检查何时手动更新,作为一个想法.

Every dataset also has an ID that maybe can be used to check when to update manually, as an idea.

推荐答案

更好的方法是在数据更改时删除对 NotifyPropertyChanged 的​​调用.

A better approach would to remove the calls to NotifyPropertyChanged whenever the data changes.

创建一个计时器并刷新计时器.这样你就可以控制刷新率,而且不受数据到达率的限制.

Create a timer and refresh on the timer. That way you can control the refresh rate, and it is not bound to the rate at which the data arrives.

这篇关于限制每秒绑定更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆