[PT Run] Retry on unavailable desktop (#17864)

* retry on unavailable desktop

* improved code
This commit is contained in:
Davide Giacometti 2022-04-27 18:10:08 +02:00 committed by GitHub
parent 2a7afa38d0
commit 0549b02315
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -83,9 +83,25 @@ namespace
inline bool GetDesktopAutomationObject(REFIID riid, void** ppv)
{
CComPtr<IShellView> spsv;
if (!FindDesktopFolderView(IID_PPV_ARGS(&spsv)))
// Desktop may not be available on startup
auto attempts = 5;
for (auto i = 1; i <= attempts; i++)
{
return false;
if (FindDesktopFolderView(IID_PPV_ARGS(&spsv)))
{
break;
}
Logger::warn(L"FindDesktopFolderView() failed attempt {}", i);
if (i == attempts)
{
Logger::warn(L"FindDesktopFolderView() max attempts reached");
return false;
}
Sleep(3000);
}
CComPtr<IDispatch> spdispView;