Discussion:
Updating paused in GUI Thread
(too old to reply)
Francis Burton
2010-02-27 17:04:48 UTC
Permalink
I have a Delphi 7 program that updates a chart many times a
second with code in an TTimer's OnTimer event. I've noticed
that when the mouse is pressed and held in a window title-
bar, the chart freezes until the mouse is released. However,
if the window is dragged around it unfreezes again. There is
also a brief freeze when the mouse is hovered over a control
that displays a tooltip, again unfreezing when the tooltip
is shown.

Although this is not a showstopper, I would like updating to
be smooth and not affected by what I do with the mouse. Does
anyone know what is going on in the scenario above, and is
there anything I can do in the code to avoid it?

Cheers,
Francis
Jamie
2010-02-27 21:00:53 UTC
Permalink
Post by Francis Burton
I have a Delphi 7 program that updates a chart many times a
second with code in an TTimer's OnTimer event. I've noticed
that when the mouse is pressed and held in a window title-
bar, the chart freezes until the mouse is released. However,
if the window is dragged around it unfreezes again. There is
also a brief freeze when the mouse is hovered over a control
that displays a tooltip, again unfreezing when the tooltip
is shown.
Although this is not a showstopper, I would like updating to
be smooth and not affected by what I do with the mouse. Does
anyone know what is going on in the scenario above, and is
there anything I can do in the code to avoid it?
Cheers,
Francis
Under some operations, GUI does not draw to the screen, the timer
most likely is still operating..

things like Keyboard and Mouse click operations tends to disable
screen painting for various reasons..

It's windblows. Live with it.
Francis Burton
2010-02-28 18:42:44 UTC
Permalink
Post by Jamie
Under some operations, GUI does not draw to the screen, the timer
most likely is still operating..
things like Keyboard and Mouse click operations tends to disable
screen painting for various reasons..
It's windblows. Live with it.
If I must, I will. I have a feeling, however, that I haven't seen
this behaviour in other programs that do frequent redraws - such
as various media players - so they must be doing something a bit
different.

Francis
Arivald
2010-02-28 20:05:11 UTC
Permalink
Post by Francis Burton
Post by Jamie
Under some operations, GUI does not draw to the screen, the timer
most likely is still operating..
things like Keyboard and Mouse click operations tends to disable
screen painting for various reasons..
It's windblows. Live with it.
If I must, I will. I have a feeling, however, that I haven't seen
this behaviour in other programs that do frequent redraws - such
as various media players - so they must be doing something a bit
different.
Put drawing in second thread... Like most media players do..

Or use window-less timer. Or multimedia timer.

There is always some way... You just must know what exactly You want to do.
--
Arivald
Maarten Wiltink
2010-03-01 08:51:46 UTC
Permalink
"Arivald" <***@interia.pl> wrote in message news:hmeifo$r85$***@news.dialog.net.pl...
[...]
Post by Arivald
Put drawing in second thread... Like most media players do..
That would seem to fly in the face of the constant warnings that you
mustn't draw from any thread but the main GUI/VCL thread.

If you are careful to never do any drawing in the main thread, is it
safe to draw from a secondary thread? Can you even prevent all drawing
from the main thread?

Or would it be easier (and would it work) to do all the other work in
a secondary thread?

Groetjes,
Maarten Wiltink
Arivald
2010-03-01 09:20:09 UTC
Permalink
Post by Maarten Wiltink
[...]
Post by Arivald
Put drawing in second thread... Like most media players do..
That would seem to fly in the face of the constant warnings that you
mustn't draw from any thread but the main GUI/VCL thread.
No... In Delphi You must not use GUI/VCL from thread.
But drawing (through GDI calls, not TCanvas) is legal and possible.

I have some controls animated from thread. Thread procedure use pure
GDI/GDI+ calls. I get DC by GetWindowDC(). And it works like charm.

VCL GUI/Thread limitations is related to fact VCL in not thread-safe. It
also can dead-lock in multi-threaded use.
Post by Maarten Wiltink
If you are careful to never do any drawing in the main thread, is it
safe to draw from a secondary thread? Can you even prevent all drawing
from the main thread?
Not a problem to draw from both threads... But in main thread You may
use VCL TCanvas. In secondary thread only pure GDI.

And, of course, you should never allow different threads to draw on same
DC (same control). iIt is why I do drawing off screen, then blit it in
one operation.
Post by Maarten Wiltink
Or would it be easier (and would it work) to do all the other work in
a secondary thread?
For me: No. It is easier to do drawing synchronously, from main thread.
I use drawing from thread only if I must. Like in animating multiple,
not related controls. Every control gets its own animating thread.
--
Arivald
Hans-Peter Diettrich
2010-03-01 04:07:07 UTC
Permalink
Post by Francis Burton
Post by Jamie
It's windblows. Live with it.
If I must, I will. I have a feeling, however, that I haven't seen
this behaviour in other programs that do frequent redraws - such
as various media players - so they must be doing something a bit
different.
My TV app. interacts directly with the graphics card. I often had my
system crashed, while TV sound and image continued.

Perhaps it helps to assign realtime attribute (priority?) to your
application, to make it more responsive?

DoDi
Loading...