开发者

Best way to measure (and control) the refresh time of some itens of the user interface

My app needs to display the process time of some operations. One of the process times is the time spent to refresh the proces times at the UI ( got it? :D ).

The frequency of the operations can vary from 0 to about 100 Hz (10 ms).

The process times are display in some labels. To set it values I use this static method:

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);
    }
}

Questions:

  1. I dont want to freeze all my UI tryng to update the process times, so how should I control whe开发者_开发技巧n is it ok to refresh? Now Im doing something like: only update if last update time was 100 ms before now.
  2. If I use BegingInvoke, is it possible to overflow the queues with too much calls?
  3. How can I measure the UI refresh time using BeginInvoke? The best way is to use Invoke?


  1. Pretty acceptable solution, by me, cause if you do not control it, it can result on data blinking on UI side.
  2. No, I don't think you can overflow, especially on 10 ms, speed.

  3. If you want to be sure on time measuring (as much as it possible) the solution is definitely is using of Invokde. The same ou an use also in production.

But this is something you gonna to measure against your specific application requirements.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜