mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 17:56:44 +02:00
properly handle thread when AOT is destroyed (#19489)
This commit is contained in:
committed by
GitHub
parent
996a235e12
commit
af4dc80ce9
@@ -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;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user