首页 > 解决方案 > Catch 22 等待外部应用程序完成处理并在完成前意外取消它

问题描述

这是我用于启动外部应用程序并等待它完成的代码的一部分:

DWORD WaitResult;
do
{
    WaitResult = MsgWaitForMultipleObjects(1,
        // only 1 wait object
        &processInformation.hProcess, // worker thread
        FALSE,   // stop if any
        INFINITE,  // no timeout
        QS_ALLINPUT);
    if (WaitResult == WAIT_OBJECT_0 + 1)
    {
        // Handle windows message
        MSG Msg;
        while (PeekMessage(&Msg, nullptr, 0, (UINT)-1, PM_REMOVE))
        {
            TRACE3("%d %d %d\n", Msg.message, Msg.wParam, Msg.lParam);
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
    }
} while (WaitResult != WAIT_OBJECT_0);
ASSERT(WaitResult == WAIT_OBJECT_0);

没关系,直到调用 exe 出现问题导致我的应用程序无限期等待。

我没有给出超时数字,因为被调用的 exe 正在与 Outlook 或 Google 同步日历事件。因此,取决于用户的互联网性能和正在同步的服务器......

有什么方法可以安全地添加一个不会实现实际过程的超时?

标签: visual-c++mfcwaitformultipleobjects

解决方案


推荐阅读