测量(和控制)用户界面某些项的刷新时间的最佳方法
我的应用程序需要显示某些操作的处理时间。处理时间之一是在 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);
}
}
问题:
- 我不想冻结所有试图更新进程时间的 UI,那么我应该如何控制何时可以刷新?现在我正在做类似的事情:仅当上次更新时间是 100 毫秒之前才更新。
- 如果我使用BegingInvoke,是否有可能因调用过多而溢出队列?
- 如何使用 BeginInvoke 测量UI 刷新时间?最好的方法是使用Invoke?
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:
- I dont want to freeze all my UI tryng to update the process times, so how should I control when is it ok to refresh? Now Im doing something like: only update if last update time was 100 ms before now.
- If I use BegingInvoke, is it possible to overflow the queues with too much calls?
- How can I measure the UI refresh time using BeginInvoke? The best way is to use Invoke?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,我认为你不会溢出,尤其是在 10 毫秒的速度上。
如果您想确保按时测量(尽可能多),解决方案肯定是使用
Invokde
。同样的 ou 也在生产中使用。但这是您需要根据您的特定应用程序要求来衡量的。
No, I don't think you can overflow, especially on 10 ms, speed.
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.