See
Multithreading: Programming Tips[
^] in the MSDN.
You did not tell us about your
CMegaDoc
class. If it is derived from
CDocument
or contains window handles, and calling member functions from the thread that access window handles, there will be assertions:
Access to a window from a thread that did not create the window is not supported by MFC. The debug assertions occur probably in
CWnd::AssertValid()
. See the source code in
wincore.cpp and the comments about multithreaded applications.
If this happens with your application, you must change the design.