mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-11-27 23:19:13 +08:00
[PT Run] Retry on unavailable desktop (#17864)
* retry on unavailable desktop * improved code
This commit is contained in:
parent
2a7afa38d0
commit
0549b02315
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user