News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

InvalidateRect and multiple threads too slow

Started by johnsa, October 23, 2009, 01:01:33 PM

Previous topic - Next topic

johnsa

Hey all,

I'm busy messing around (first time in a long time) with a std. win32 gui. I have an skinned window setup, std message loop and WndProc with WM_PAINT etc.
My main processing happens in a seperate thread which calls InvalidateRect (using a dirty region) just to update a progress bar image which is draw in the WM_PAINT. The second I add the invalidateRect, even though it's a tiny little portion of the screen it slows the whole app dowm by orders of magnitude. The update is called to equate to every 1% based on the number of records being processed.

I was thinking of using SetDIBitsToDevice or something else, maybe being able to get the bitmap to update directly without going via invalidateRect or WM_PAINT?

Any thoughts how to get this setup a bit faster?
Thanks
John

Mirno

Do you know how often this condition is firing?
Replace the code with something that'll get the time, and add it to a buffer. Then print out the buffer at the end.

Secondly, don't have your worker thread do this work - it's a worker thread, not a GUI thread. There are a bunch of reserved messages in windows, take one and use it for your own purposes. Maybe combine this with a timer, so that you can only update once every nth of a second (play with the value of n for smoothness etc.).

So worker thread will send message WM_MY_NEED_UPDATE

GUI thread will on receiving WM_MY_NEED_UPDATE set a flag, or do the work directly (try both).

*optional* Set timer, on getting the WM_TIMER event, check the flag set in WM_MY_NEED_UPDATE, and if set, do the invalidation & associated repainting.

Mirno