#include <windows.h>
#include "process.h"
class Callback_Base
{
public:
Callback_Base()
{
bRunThread = true;
};
~Callback_Base()
{
WaitForSingleObject(mCallbackThread, 1000);
CloseHandle(mCallbackThread);
mCallbackThread = NULL;
};
protected:
void startCallBackThread();
static unsigned int __stdcall callBackThread(void *param);
unsigned int innerCallBackThread();
private:
bool bRunThread;
HANDLE g_hEvent;
HANDLE mCallbackThread;
};
void Callback_Base::startCallBackThread()
{
if (!mCallbackThread)
{
g_hEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
mCallbackThread = (HANDLE)_beginthreadex(NULL, 0, &Callback_Base::callBackThread, this, 0, NULL);
}
}
unsigned int __stdcall Callback_Base::callBackThread( void *param )
{
Callback_Base *pThis = (Callback_Base*)param;
if (pThis)
{
return pThis->innerCallBackThread();
}
return 0;
}
unsigned int Callback_Base::innerCallBackThread()
{
while (bRunThread)
{
Sleep(1000);
sleepTime++;
}
return 1;
}