问题
I have MFC application that pops up a server busy dilaog that looks just like here: https://stackoverflow.com/questions/4968872/how-can-i-disable-the-ole-server-busy-dialog-in-a-c-sharp-app
This app calls AfxOleInit(). http://support.microsoft.com/kb/248019 explains that i should do AfxOleGetMessageFilter()->SetMessagePendingDelay(nTimeout); to avoid getting the dialog. It also suggest that i use OleInitialize instead of AfxOleInit to suppress the dialog.
Does this mean if i don't call AfxOleInit(), then i won't get the server busy dialog? I can't really test because without AfxOleInit(), AfxOleGetMessageFilter returns null pointer so I can't really set it to 1ms and test if it pops up a dialog when it times out.
So my question is, if i don't call AfxOleInit then would i ever get "server busy" dialog?
Thanks
回答1:
Look, the call to AfxOleInit does pretty the same as 'OleInitialize' which internally invokes 'CoInitialize'.
It initializes the COM environment, so you may then use OLE automation, rich OLE containers, ActiveX controls and e.t.c. But additionality it installs a message filter which you may then acquire with AfxOleGetMessageFilter(). This message filter is dedicate to handle situations, when an OLE request blocks UI for too long.
So if you call OleInitialize instead of 'AfxOleInit' no message filter will be installed, and thus you will not see the "Server is busy" dialog and AfxOleGetMessageFilter() will point to NULL.
Also as suggested in the article, you may use
AfxOleInit()
....
AfxOleGetMessageFilter()->EnableNotRespondingDialog(FALSE);
to disable this dialog.
But your best bet would be to find the underlying problem.
来源:https://stackoverflow.com/questions/9577052/com-server-busy-dialog-on-mfc