我的应用需要显示一些操作的处理时间。处理时间之一是在 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?