mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-11-24 12:25:12 +08:00
Fix race-condition in PowerRename progress UI (#12771)
This commit is contained in:
parent
ec08a1d44a
commit
31a5d49246
@ -1525,7 +1525,11 @@ HRESULT CPowerRenameProgressUI::Start()
|
||||
m_canceled = false;
|
||||
AddRef();
|
||||
m_workerThreadHandle = CreateThread(nullptr, 0, s_workerThread, this, 0, nullptr);
|
||||
if (!m_workerThreadHandle)
|
||||
if (m_workerThreadHandle)
|
||||
{
|
||||
m_loadingThread = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Release();
|
||||
}
|
||||
@ -1557,6 +1561,7 @@ DWORD WINAPI CPowerRenameProgressUI::s_workerThread(_In_ void* pv)
|
||||
SetTimer(hwndMessage, TIMERID_CHECKCANCELED, CANCEL_CHECK_INTERVAL, nullptr);
|
||||
sppd->StartProgressDialog(NULL, NULL, PROGDLG_MARQUEEPROGRESS, NULL);
|
||||
}
|
||||
pThis->m_loadingThread = false;
|
||||
|
||||
while (pThis->m_sppd && !sppd->HasUserCancelled())
|
||||
{
|
||||
@ -1591,6 +1596,11 @@ HRESULT CPowerRenameProgressUI::Stop()
|
||||
|
||||
void CPowerRenameProgressUI::_Cleanup()
|
||||
{
|
||||
while (m_loadingThread.load())
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||
}
|
||||
|
||||
if (m_sppd)
|
||||
{
|
||||
m_sppd->StopProgressDialog();
|
||||
|
@ -68,6 +68,7 @@ private:
|
||||
|
||||
long m_refCount = 0;
|
||||
bool m_canceled = false;
|
||||
std::atomic<bool> m_loadingThread{ false };
|
||||
HANDLE m_workerThreadHandle = nullptr;
|
||||
CComPtr<IProgressDialog> m_sppd;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user