我的C ++应用程序每隔一段时间就会使用基于此页面的MSDN示例的代码遍历多个应用程序的MSAA树:https://msdn.microsoft.com/en-us/library/windows/desktop/dd317975(v=vs.85).aspx
它工作得很好,直到几个月前我开始注意到有时线程冻结在AccessibleChildren调用上。
以下是我所知道的:
childCount
标记为1的小型转储,它绝对没有连接到当前节点的子节点数。我的问题是:有人可以指出这种冻结的原因以及如何预防这些原因吗?如果没有,有没有办法将递归移动到另一个线程,这可以安全地从另一个线程“超时”?
这是此类事件的示例堆栈跟踪,其中top是最嵌套的调用。我从这里删除了我的递归,以缩短读数。
--> ntdll.dll!_NtWaitForMultipleObjects@20() Unknown
ntdll.dll!_NtWaitForMultipleObjects@20() Unknown
KERNELBASE.dll!_WaitForMultipleObjectsEx@20() Unknown
kernel32.dll!_WaitForMultipleObjectsExImplementation@20() Unknown
user32.dll!_RealMsgWaitForMultipleObjectsEx@20() Unknown
ole32.dll!CCliModalLoop::BlockFn(void * * ahEvent, unsigned long cEvents, unsigned long * lpdwSignaled) Line 1222 C++
ole32.dll!ModalLoop(CMessageCall * pcall) Line 211 C++
ole32.dll!ThreadSendReceive(CMessageCall * pCall) Line 4979 C++
ole32.dll!CRpcChannelBuffer::SwitchAptAndDispatchCall(CMessageCall * * ppCall) Line 4454 C++
ole32.dll!CRpcChannelBuffer::SendReceive2(tagRPCOLEMESSAGE * pMessage, unsigned long * pstatus) Line 4076 C++
ole32.dll!CCliModalLoop::SendReceive(tagRPCOLEMESSAGE * pMsg, unsigned long * pulStatus, IInternalChannelBuffer * pChnl) Line 899 C++
ole32.dll!CAptRpcChnl::SendReceive(tagRPCOLEMESSAGE * pMsg, unsigned long * pulStatus) Line 583 C++
ole32.dll!CCtxComChnl::SendReceive(tagRPCOLEMESSAGE * pMessage, unsigned long * pulStatus) Line 659 C++
ole32.dll!NdrExtpProxySendReceive(void * pThis, _MIDL_STUB_MESSAGE * pStubMsg) Line 1932 C++
rpcrt4.dll!@NdrpProxySendReceive@4() Unknown
rpcrt4.dll!_NdrClientCall2() Unknown
ole32.dll!ObjectStublessClient(void * ParamAddress, long Method) Line 474 C++
ole32.dll!_ObjectStubless@0() Line 154 Unknown
ole32.dll!CStdMarshal::Begin_RemQIAndUnmarshal1(unsigned short cIIDs, _GUID * pIIDs, tagQICONTEXT * pQIC) Line 4551 C++
ole32.dll!CStdMarshal::Begin_QueryRemoteInterfaces(unsigned short cIIDs, _GUID * pIIDs, tagQICONTEXT * pQIC) C++
ole32.dll!CStdMarshal::QueryRemoteInterfaces(unsigned short cIIDs, _GUID * pIIDs, tagSQIResult * pQIRes) Line 4284 C++
ole32.dll!CStdIdentity::CInternalUnk::QueryMultipleInterfaces(unsigned long cMQIs, tagMULTI_QI * pMQIs) Line 596 C++
ole32.dll!CStdIdentity::CInternalUnk::QueryInterface(const _GUID & riid, void * * ppv) Line 352 C++
ole32.dll!IUnknown_QueryInterface_Proxy(IUnknown * This, const _GUID & riid, void * * ppv) Line 1723 C++
ole32.dll!CoUnmarshalInterface(IStream * pStm, const _GUID & riid, void * * ppv) Line 996 C++
oleacc.dll!UnmarshalInterface(unsigned char const *,unsigned long,struct _GUID const &,void * *) Unknown
oleacc.dll!FreeUpSlot(struct OutstandingObjectEntry *) Unknown
oleacc.dll!_ObjectFromLresult@16() Unknown
oleacc.dll!NativeIAccessibleFromWindow(struct HWND__ *,unsigned long,struct _GUID const &,void * *) Unknown
oleacc.dll!_ORIGINAL_AccessibleObjectFromWindow@16() Unknown
oleacc.dll!_AccessibleObjectFromWindow@16() Unknown
oleacc.dll!GetWindowObject(struct HWND__ *,struct tagVARIANT *) Unknown
oleacc.dll!CClient::Next(unsigned long,struct tagVARIANT *,unsigned long *) Unknown
oleacc.dll!AccWrap_Base::Next(unsigned long,struct tagVARIANT *,unsigned long *) Unknown
oleacc.dll!_AccessibleChildren@20() Unknown
//my recursion ends here
答案 0 :(得分:0)
我仍然不知道上面为什么会发生这种情况以及如何在我的代码中保护我的应用程序。我认为自己唯一的解决方案是使用单独的进程并等待一段时间超时。像this Microsoft example之类的东西,但是超时设置为常量值(比如半秒)而不是INFINITE
。
如果因为进程完成等待结束,那么我会把它作为响应的stdout(一些json与结果或类似的东西)。如果处理时间超过我将简单地终止它以清理其资源。
不是一个完美的解决方案,但它会让我对正在发生的事情有所控制,我会以某种方式防止内存泄漏等。
由于这只是一半,我很乐意接受任何其他想法来解决我的问题。