我的app需要显示一些操作的进程时间。其中一个流程时间是用于在UI上刷新流程的时间(明白了吗?: D)。
操作频率范围为0 ~ 100hz(约10ms)。
在一些标签中显示处理时间。为了设置它的值,我使用以下静态方法:
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,是否有可能溢出队列与太多的调用?
- 如何测量UI刷新时间使用BeginInvoke?最好的方法是使用Invoke?
- 相当可接受的解决方案,对我来说,因为如果你不控制它,它可以导致数据在UI端闪烁。
-
不,我不认为你可以溢出,特别是在10毫秒,速度。
-
如果你想确保准时测量(尽可能多),解决方案肯定是使用
Invokde
。
但这是你要根据你的具体应用需求来衡量的。