0

我的应用需要显示一些操作的处理时间。处理时间之一是在 UI 上刷新处理时间所花费的时间(明白吗?:D)。

操作的频率可以在 0 到大约 100 Hz (10 ms) 之间变化。

处理时间显示在一些标签中。要设置它的值,我使用这个静态方法:

public Class UserInteface
{
    //Static action to SafeSetControlText
    private static Action<Control, string> actionSetControlText = delegate(Control c, string txt) { c.Text = txt; };

    //Control
    //Set Text
    public static void SafeSetControlText(Control control, string text, bool useInvoke = false)
    {
        //Should I use actionSetControlText or it is ok to create the delegate every time?
        Action<Control, string> action = delegate(Control c, string txt) { c.Text = txt; };
        if (control.InvokeRequired)
        {
            if (useInvoke)
                control.Invoke(action, new object[] { control, text });
            else
                control.BeginInvoke(action, new object[] { control, text });
        }
        else
            action(control, text);
    }
}

问题:

  1. 我不想冻结我所有的 UI 尝试更新进程时间,那么我应该如何控制何时可以刷新?现在我正在做类似的事情:只有在上次更新时间是现在之前的 100 毫秒时才更新。
  2. 如果我使用 BegingInvoke,是否有可能因调用过多而导致队列溢出?
  3. 如何使用 BeginInvoke测量UI 刷新时间?最好的方法是使用 Invoke?
4

1 回答 1

1
  1. 我可以接受的解决方案,因为如果你不控制它,它可能会导致 UI 端的数据闪烁。
  2. 不,我认为您不会溢出,尤其是在 10 毫秒的速度下。

  3. 如果您想确保按时测量(尽可能多),那么解决方案肯定是使用Invokde. 在生产中也有同样的用途。

但这是您要根据您的特定应用程序要求来衡量的东西。

于 2011-09-11T18:16:16.487 回答