Best way to measure (and control) the refresh time of some itens of the user interface
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 whe开发者_开发技巧n 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?
- Pretty acceptable solution, by me, cause if you do not control it, it can result on data blinking on UI side.
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.
精彩评论