Groups | Blog | Home
all groups > dotnet performance > october 2003 >

dotnet performance : Windows message queue question


Markus Minichmayr
10/22/2003 9:34:53 PM
Hi all!

I'm writing a windows application, that contains a control that shows a
bitmap. The bitmap is painted in the controls OnPaint method, using the
Graphics.DrawImage method. It is possible to drag the bitmap around inside
the control, using the mouse. While dragging the image, I call the controls'
Invalidate method every time i get a MouseMove-event. So far so good. The
problem is, that, when the image is large and I drag it around and then stop
moving the mouse, the image often still keeps moving over the control for a
few more seconds. I guess, this is caused by MouseMove events, still
contained in the applications message queue. A profiling utility showed,
that OnPaint was called exactly as often as MouseMove. I was surprised about
that, since I thought that OnPaint would be called asynchronously and only
when there is time for.

Can anybody explain this to me? How can it happen, that there are MouseMove
events in the queue for such a long time and why is OnPaint obviously called
every single time, Invalidate is called? (I don't call Update!)
Is there a possibility, to drop all MouseMove and Paint events, currently
contained in the message queue, except the last ones?
Does anyone know another solution for the problem?
If this is the wrong NG for my question, wher else should I post it?

Any comments would be appreciated.

Thanks
Markus

shawnr NO[at]SPAM online.microsoft.com (
10/30/2003 10:36:44 PM
Hi Markus-

Why are you calling Invalidate explicitly? Calling Invalidate puts redraws
into your Windows message queue to be executed as they are dequeued while
Update will force a redraw of all Invalidated regions to be painted right
when you call it. You're right that OnPaint is called async and only when
there is time for it, but the time to redraw your image is unknown (varies
based on the size of your image) when the message pump grabs the next item
in the queue and executes it. By the time you are done moving the mouse,
all your Invalidates are queued up and the message pump still has to take
the rest of them and repaint for each of them.

--
This posting is provided "AS IS" with no warranties, and confers no rights.

Thanks
Shawn Rothlisberger
CLR Performance Test
AddThis Social Bookmark Button