I have a MFC code based on Document View framework. I use UpdateAllViews(nullptr,0,nullptr) from Document class to invoke the View's OnDraw member function.
void MyDocumentClass::MyFunction()
{
//.. Document code to create and process data
UpdateAllViews(nullptr,0,nullptr) // Invokes OnDraw
// When does program control reach this line?
}
My question is, please tell me if the UpdateAllViews function is blocking or non blocking, when does program control reach the line next to UpdateAllViews()? Does it reach there after all the code in OnDraw() has finished executing, or does it reach there sooner?
UpdateAllViews is a nonblocking function that simply calls OnUpdate of each view. The OnUpdate function typically invalidates the view, which will cause OnDraw later. UpdateAllViews returns after the invalidating and before the painting.
UpdateAllViews is a blocking function that simply loops each view and calls their OnUpdate function. It is not a "queue for later" and return immediately call like PostMessage.
Like SendMessage, UpdateAllViews does not return until all of the code in each view's OnUpdate function has been executed. That is why doing something heavy like like directly calling OnDraw or blocking I/O in UpdateAllViews/OnUpdate is typically a bad idea. It is a better practice to invalidate some or all of the views based on the hint parameters and let the framework call OnDraw on the next WM_PAINT.