GDI or GDI+ from worker thread safely?
-
Hey guys, I have an application where I need to keep the UI responsive while background tasks are running. I currently have worker thread that does a PostMessage to a handler that does my GDI drawing, but the problem is that if too many things are happening the message pump gets held up and therefor my UI drawing is not smooth at times. If there was some way I could just do my GDI or GDI+ drawing directly from the worker thread I know that would solve my problems and my UI would be responsive. Is there anyway I can do my drawing directly from a woker thread safely using either GDI, GDI+, or even DirectX? any way at all?
-
Hey guys, I have an application where I need to keep the UI responsive while background tasks are running. I currently have worker thread that does a PostMessage to a handler that does my GDI drawing, but the problem is that if too many things are happening the message pump gets held up and therefor my UI drawing is not smooth at times. If there was some way I could just do my GDI or GDI+ drawing directly from the worker thread I know that would solve my problems and my UI would be responsive. Is there anyway I can do my drawing directly from a woker thread safely using either GDI, GDI+, or even DirectX? any way at all?
You can do your drawing into off screen buffers in the worker thread then signal the main thread to update the display and all it has to do is draw the buffer(s) making it much faster. But you haven't indicated what you are actually doing so I don't know if that is helpful.
led mike
-
You can do your drawing into off screen buffers in the worker thread then signal the main thread to update the display and all it has to do is draw the buffer(s) making it much faster. But you haven't indicated what you are actually doing so I don't know if that is helpful.
led mike
Oh cool, so I can actually safely use GDI calls to draw on an offscreen device context from directly within the thread so long as I dont do anything with an actual windows control? Then just update the actual windows control from the main thread?
modified on Wednesday, February 27, 2008 11:41 AM
-
Oh cool, so I can actually safely use GDI calls to draw on an offscreen device context from directly within the thread so long as I dont do anything with an actual windows control? Then just update the actual windows control from the main thread?
modified on Wednesday, February 27, 2008 11:41 AM
Greg Ellis wrote:
so I can actually safely use GDI calls to draw on the device context from directly within the thread
Safely? Not without synchronization. You have to insure the user can't do anything to cause GDI ops - like dragging a window across your windows, etc. It is possible, but safely takes some work :) If you use regular thread synchronization to control all thread access to GDI then it will work pretty well. I've been doing it for a lot of years, including rendering video and graphics on windows of another process, and I've not seen or heard of any problems yet. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: