#pragma once
#include <Windows.h>
class AutoResetEvent
{
private:
HANDLE m_waitEvent;
public:
AutoResetEvent(bool bManualReset)
{
m_waitEvent = CreateEvent(NULL, bManualReset, false, NULL);
}
~AutoResetEvent()
{
if (m_waitEvent)
{
CloseHandle(m_waitEvent);
m_waitEvent = NULL;
}
}
bool WaitOne(DWORD dwWaitTimeMillSeconds)
{
return WaitForSingleObject(m_waitEvent, dwWaitTimeMillSeconds) == WAIT_OBJECT_0;
}
bool Set()
{
return SetEvent(m_waitEvent);
}
bool Reset()
{
return ResetEvent(m_waitEvent);
}
};