The following code assumes MFC document view architecture. doc_data is a CString data member of the document. The issue is that calling UpdateAllViews causes doc_data to be displayed, but the string that is displayed has not been assigned until after the call to UpdateAllViews. This behaviour can be prevented by uncommenting the message box line so as to force a moment's wait.
// CMainFrame message handlers
void CMainFrame::OnViewTest()
{
CView* vwd = (GetActiveView());
CMFCApplicationxxDoc* pDoc{};
if (vwd)
pDoc = dynamic_cast<CMFCApplicationxxDoc*>(vwd->GetDocument());
if (pDoc) {
pDoc->doc_data = "New data";
pDoc->UpdateAllViews(NULL);
//AfxMessageBox(_T("Wait a moment"));
pDoc->doc_data = "Even newer data";
}
}
This has been previously explained: "The OnUpdate function typically invalidates the view, which will cause OnDraw later. UpdateAllViews returns after the invalidating and before the painting" in Is MFC UpdateAllViews blocking or non blocking?
This could cause a problem. For example, if data is shown in a graph, some values might be updated, and some not. So my question is: What is a good way to ensure (without user input) that all current data is displayed correctly before the program goes on to modify it?