#pragma once // // Helper class to manage Win32 event objects. // class CAutoResetEvent { public: HANDLE m_hEvent; // handle to Win32 event object CAutoResetEvent(bool bInit = true, LPCWSTR pwszName = NULL) { m_hEvent = NULL; if(bInit) Init(pwszName); } ~CAutoResetEvent() { if(m_hEvent != NULL) CloseHandle(m_hEvent); } bool Init(LPCWSTR pwszName = NULL) { if(m_hEvent == NULL) m_hEvent = CreateEvent(NULL, FALSE, FALSE, pwszName); return (m_hEvent != NULL); } void Set() { if(m_hEvent != NULL) SetEvent(m_hEvent); } DWORD Wait(DWORD dwTimeout = INFINITE) { if(m_hEvent == NULL) return ERROR_INVALID_HANDLE; return WaitForSingleObject(m_hEvent, dwTimeout); } };
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)