I have a MFC document/view C++ graphics application that does all its drawing to an off screen bitmap, and then copys that to the supplied CDC pointer in the OnDraw method. Over the last couple of days I've been looking to place the drawing component in a seperate worker thread, so it doesn't stall the GUI. I seem to get a fair number of MFC GDI related asserts firing when I do this, e,g,
VERIFY(::MoveToEx(m_hAttribDC, x, y, &point)
So a few questions;
- Are there any problems with using worker threads with MFC & GDI?
- Are there issues using MFC GDI objects across threads?
- Do GDI objects have to be declared locally to a thread?
While it is possible the issue is resource/locking related, the drawing thread has its own provate CDC and CBitmap that it uses for all the drawing, and only copies the bitmap back to the main thread when it hasz excludive access via a mutex. The code has also been tested by direct calling rather than as a seperate thread to prove the problem does relate to threading.