私のアプリは、いくつかの操作の処理時間を表示する必要があります。処理時間の 1 つは、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 を使用することですか?