From 0f55256262b056bce34e3a7bb5cfee36b037996a Mon Sep 17 00:00:00 2001 From: Mykhailo Pylyp Date: Wed, 25 Aug 2021 18:21:54 +0300 Subject: [PATCH] Remove retries (#12860) --- src/common/utils/process_path.h | 46 ++++++++++++++------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/src/common/utils/process_path.h b/src/common/utils/process_path.h index e04f4739a4..726c5db3ce 100644 --- a/src/common/utils/process_path.h +++ b/src/common/utils/process_path.h @@ -42,33 +42,27 @@ inline std::wstring get_process_path(HWND window) noexcept // It might take a time to connect the process. That's the reason for the retry loop here DWORD new_pid = pid; - const int retryAttempts = 10; - for (int retry = 0; retry < retryAttempts && pid == new_pid; retry++) + EnumChildWindows( + window, [](HWND hwnd, LPARAM param) -> BOOL { + auto new_pid_ptr = reinterpret_cast(param); + DWORD pid; + GetWindowThreadProcessId(hwnd, &pid); + if (pid != *new_pid_ptr) + { + *new_pid_ptr = pid; + return FALSE; + } + else + { + return TRUE; + } + }, + reinterpret_cast(&new_pid)); + + // If we have a new pid, get the new name. + if (new_pid != pid) { - EnumChildWindows( - window, [](HWND hwnd, LPARAM param) -> BOOL { - auto new_pid_ptr = reinterpret_cast(param); - DWORD pid; - GetWindowThreadProcessId(hwnd, &pid); - if (pid != *new_pid_ptr) - { - *new_pid_ptr = pid; - return FALSE; - } - else - { - return TRUE; - } - }, - reinterpret_cast(&new_pid)); - - // If we have a new pid, get the new name. - if (new_pid != pid) - { - return get_process_path(new_pid); - } - - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + return get_process_path(new_pid); } }