I was digging into usage of wil::wait_for_completion_or_timeout_nothrow(), from wil\winrt.h
And was observing a strange behaviour, where it would clearly timeout, but it fails with 0x8000000e (E_ILLEGAL_METHOD_CALL) instead of success.
With this bug, I cannot properly do this logic:
DWORD threadTimeoutMs = 1000;
RETURN_IF_FAILED(wil::wait_for_completion_or_timeout_nothrow(asyncUpdateOp.get(), threadTimeoutMs, &bTimedOut));
RETURN_HR_IF(HRESULT_FROM_WIN32(ERROR_TIMEOUT), bTimedOut);
because it would always fail out with 0x8000000e, before letting me error out with ERROR_TIMEOUT.
I tracked it down to where WaitForCompletion would return S_OK with timedOut = true.
But the next line, GetResults() would fail because the operation was not completed yet, thus returning 0x8000000e.
template <typename TIOperation, typename TIResults>
HRESULT WaitForCompletion(In TIOperation operation, Out TIResults result, COWAIT_FLAGS flags,
DWORD timeoutValue, Out_opt bool* timedOut) WI_NOEXCEPT
{
RETURN_IF_FAILED_EXPECTED(details::WaitForCompletion(operation, flags, timeoutValue, timedOut));
return operation->GetResults(result);
}
The fix should be to check if (!timedOut) { return operation->GetResults(result); } else return S_OK;