Reputation: 471
Following all information I found, GDI+ is capable to be used in a muli-threaded way, with just the restriction that a GDI+ object must not be used from several threads at the same time.
I have the problem of sporadic crashed of two threads in my C++ MFC Windows application (one cares for the splash window while startup, the other is the main thread doing some initialization stuff). The crashes are not reproducible, but have one thing in common: At least one of these both threads is in a GDI+ operation in the moment the program is stopped in the debugger.
Does anyone out here know something about GDI+ threading?
Upvotes: 1
Views: 1725
Reputation: 7170
It is better to use the "double buffer" mechanism to create 2 memory DCs for each map, use one by one. That is to say, the main window reads the memory DC A for display while the background thread draws on the memory DC B, and informs the main thread when the drawing is completed. After the main thread is notified, A and B are exchanged (B is displayed, and A is the object of the next background thread operation).
About GdiplusStartup:
You can call GdiplusStartup on one thread and call GdiplusShutdown on another thread as long as you delete all of your GDI+ objects (or have them go out of scope) before you call GdiplusShutdown.
The document also includes some other usage on it. It also mentions how to use dynamic data exchange (DDE) with GDI+:
If you want to initialize GDI+ for your application (by calling GdiplusStartup in your InitInstance function), you have to suppress the GDI+ background thread.
Upvotes: 1