Catch 22 with waiting for external application to finish processing and accidentally cancelling it before finishing

38 views Asked by At

This is part of my code for launching an external application and waiting for it to finish:

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);

It is fine, until there is some issue with the calling exe that causes my app to indefinitely wait.

I did not put a figure for the time out because the exe being called is synchronizing calendar events with Outlook or Google. So depending on the users internet performance and the servers being synced with ...

Is there any way that I can safely add a time out that will not implement the actual process?

0

There are 0 answers