0

私のアプリは、いくつかの操作の処理時間を表示する必要があります。処理時間の 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);
    }
}

質問:

  1. 処理時間を更新しようとしてすべての UI をフリーズさせたくないので、更新のタイミングをどのように制御すればよいですか? 今、私は次のようなことをしています: 最後の更新時間が今から 100 ミリ秒前の場合にのみ更新します。
  2. BegingInvoke を使用すると、呼び出しが多すぎてキューがオーバーフローする可能性はありますか?
  3. BeginInvoke を使用してUI の更新時間を測定するにはどうすればよいですか? 最良の方法は、Invoke を使用することですか?
4

1 に答える 1

1
  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.

于 2011-09-11T18:16:16.487 に答える