Tuesday, December 7, 2010

"Server Busy" and AfxOleInit

Recently, we had one problem of showing "Server Busy" dialog during the long time WaitHandle.WaitOne waiting, kind of annoying. After research work, found the reason. Maybe it is by design of Microsoft, to provide opportunities for calls to a com thread which is already blocked by any wait or sleep functions to deal the situation correctly, like retry or cancel. While, this may not be expected as most users do.

The work-around is simple, since AfxOleInit() register a COleMessageFilter internally, which calls CoRegisterMessageFilter. So, we can just register it again and calling EnableBusy and EnableBusyDialog(FALSE).

Another solution is to call OleInitialize or CoInitializeEx with apartment thread model instead of AfxOleInit().

No comments:

Post a Comment