, m_filePath{filePath}
, m_dwThreadId(0)
, m_hThread(nullptr)
+ , m_hEvent(nullptr)
{
m_iniFileKeyValues = Load(m_filePath);
+ m_hEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr);
m_hThread = reinterpret_cast<HANDLE>(
_beginthreadex(nullptr, 0, AsyncWriterThreadProc, this, 0,
reinterpret_cast<unsigned *>(&m_dwThreadId)));
+ WaitForSingleObject(m_hEvent, INFINITE);
+ CloseHandle(m_hEvent);
+ m_hEvent = nullptr;
}
CIniOptionsMgr::~CIniOptionsMgr()
CIniOptionsMgr *pThis = reinterpret_cast<CIniOptionsMgr *>(pvThis);
MSG msg;
BOOL bRet;
+ // create message queue
+ PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
+ SetEvent(pThis->m_hEvent);
while ((bRet = GetMessage(&msg, 0, 0, 0)) != 0)
{
auto* pParam = reinterpret_cast<AsyncWriterThreadParams *>(msg.wParam);
, m_bCloseHandle(false)
, m_dwThreadId(0)
, m_hThread(nullptr)
+ , m_hEvent(nullptr)
, m_dwQueueCount(0)
{
InitializeCriticalSection(&m_cs);
+ m_hEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr);
m_hThread = reinterpret_cast<HANDLE>(
_beginthreadex(nullptr, 0, AsyncWriterThreadProc, this, 0,
reinterpret_cast<unsigned *>(&m_dwThreadId)));
+ WaitForSingleObject(m_hEvent, INFINITE);
+ CloseHandle(m_hEvent);
+ m_hEvent = nullptr;
}
CRegOptionsMgr::~CRegOptionsMgr()
CRegOptionsMgr *pThis = reinterpret_cast<CRegOptionsMgr *>(pvThis);
MSG msg;
BOOL bRet;
+ // create message queue
+ PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
+ SetEvent(pThis->m_hEvent);
while ((bRet = GetMessage(&msg, 0, 0, 0)) != 0)
{
auto* pParam = reinterpret_cast<AsyncWriterThreadParams *>(msg.wParam);
{
auto* pParam = new AsyncWriterThreadParams(name, value);
InterlockedIncrement(&m_dwQueueCount);
- PostThreadMessage(m_dwThreadId, WM_USER, (WPARAM)pParam, 0);
+ if (!PostThreadMessage(m_dwThreadId, WM_USER, (WPARAM)pParam, 0))
+ InterlockedDecrement(&m_dwQueueCount);
}
return retVal;
}