diff --git a/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.cpp b/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.cpp index b0493c7c8e..aae0ad2303 100644 --- a/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.cpp +++ b/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.cpp @@ -56,11 +56,12 @@ AlwaysOnTop::~AlwaysOnTop() { if (m_hPinEvent) { - SetEvent(m_hPinEvent); - m_thread.join(); CloseHandle(m_hPinEvent); } + m_running = false; + m_thread.join(); + CleanUp(); } @@ -274,12 +275,12 @@ void AlwaysOnTop::RegisterLLKH() Logger::warn(L"Failed to create pinEvent. {}", get_last_error_or_default(GetLastError())); return; } - + m_thread = std::thread([this]() { MSG msg; - while (1) + while (m_running) { - DWORD dwEvt = MsgWaitForMultipleObjects(1, &m_hPinEvent, false, INFINITE, QS_ALLINPUT); + DWORD dwEvt = MsgWaitForMultipleObjects(1, &m_hPinEvent, false, 0, QS_ALLINPUT); switch (dwEvt) { case WAIT_OBJECT_0: @@ -296,7 +297,7 @@ void AlwaysOnTop::RegisterLLKH() } break; default: - return false; + break; } } }); diff --git a/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.h b/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.h index 663aae65ba..91a18cc5af 100644 --- a/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.h +++ b/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.h @@ -50,6 +50,7 @@ private: HANDLE m_hPinEvent; std::thread m_thread; const bool m_useCentralizedLLKH; + bool m_running = true; LRESULT WndProc(HWND, UINT, WPARAM, LPARAM) noexcept; void HandleWinHookEvent(WinHookEvent* data) noexcept;