tags:

views:

1482

answers:

4

I have a Windows form application written in C#. I update the title of the form frequently, but there's a substantial lag between the title changing and the title dislayed in the taskbar being updated.

What's a clean way to force an update / redraw of the task bar's entry for my program? Failing that, how can I force a redraw of the entire task bar?

Elaboration: It turns out that the delay in updating the taskbar is fixed at about 100ms, however this seems to be a delay based on when the Form.Text was last modified. If you modify the text faster then that - say, every 10ms, the taskbar is not updated until the Form.Text has been left unchanged for at least ~100ms.

OS: Vista 32.

+1  A: 

Did you try to call Form.Refresh() after updating the title?

Edit:

If you are doing the title updates in a loop you might have to do something along the line of:

        this.Invalidate();
        this.Update();
        Application.DoEvents();
Jonas Elfström
aAe, doesn't affect the taskbar. Also tried other assorted updates, hide/shows, etc.
Blinky
No not directly. Are you performing the updates in some kind of loop?
Jonas Elfström
Yes, the application is a timer. On each tick, I want to update the title to the current time remaining.
Blinky
See elaboration.
Blinky
+1  A: 

I just did a simple test. The changes are quite instantaneous. From the look of it, it's definitely less than 500ms. If you need to update the title at a higher rate, I won't really recommend it. Generally I've seen the fastest update rate of twice per second.

EDIT: I tested using keypress event. When I hold down the key for a fast repeat, it won't update until I've release my key. Thus, same scenario as your setup.

Btw, why do you need to update every 10ms? Just keep in mind that Thread.Sleep(timeout) with timeout of less than 50ms is not accurate. Also, 10ms timeout will equal to 100Hz, unless you're using high end display, you'll have miss a few frame. Most general LCD have a refresh rate of 60Hz. And our eye can't differentiate anything faster than 25Hz. Thus 40ms delay is more than enough, if you want to animate. Generally I would recommend 15Hz (67ms) for simple animation. If just want to scroll some text, 2Hz is more than enough. Anything faster will make the user dizzy.

faulty
I also did a quick test and a this.Text = DateTime.Now.ToLongTimeString(); in a click button event updates the taskbar in under a second on my machine.
Jonas Elfström
Curious, I'm not getting that behavior. Are you in XP or Vista? Perhaps it's a Vista thing.
Blinky
See elaboration.
Blinky
+2  A: 

A task bar update more than every 100ms is going to be too fast for the user to resolve anyway. Presumably you're showing some sort of progress or status indicator to the user?

If so, you're crippling the app needlessly doing so many UI updates. That processing time is better used getting the customer's job done.

I think you need to revisit the UI design aspects of what you're trying to do.

WOPR
I disagree; when displaying progress percentage in title, update every ~100+ milliseconds yields fairly "choppy" experience (equivalent of 10FPS; our eyes usually perceive 30+FPS as smooth, i.e. ~35 milliseconds).
Milan Gardian
+1  A: 

Are you using code similar to this in your form?:

    private void Form1_Load(object sender, EventArgs e)
    {
        Timer t = new Timer();
        t.Interval = 10;
        t.Tick += new EventHandler(t_Tick);
        t.Start();
    }

    int aa = 0;

    void t_Tick(object sender, EventArgs e)
    {
        this.Text = aa++.ToString();
    }

Works fine for me - no lag between form and taskbar at all.

Are you sure you aren't locking up the GUI thread and not calling Application.DoEvents on your loop?

I'm using the new Windows 7 beta, so it's a small chance that it's different behavior.

TheSoftwareJedi
This is equivalent to my code, yes. I just tested your code on my Vista machine, and the lag persists. Perhaps there is an outside obfuscating factor to this? It could be that Windows 7 is doing it differently, or perhaps it relates to system settings that apply to Aero or some such.
Blinky