⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loopthread.cpp

📁 A3服务端AccountServer源代码
💻 CPP
字号:
// LoopThread.cpp: implementation of the CThread class.
//
//////////////////////////////////////////////////////////////////////
#include <process.h>
#include "LoopThread.h"


//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CLoopThread::CLoopThread()
{
	m_bRunThread = FALSE;
	m_hThread = INVALID_HANDLE_VALUE;
}

CLoopThread::~CLoopThread()
{
	CloseThread();
}

unsigned int __stdcall CLoopThread::ThreadFunction(void *lpParam)
{
	CLoopThread* pThis = (CLoopThread*)lpParam;
	pThis->LoopProc();

	return 0;
}

BOOL CLoopThread::BeginThread()
{
	if (m_bRunThread) return FALSE;

	m_hThread = (HANDLE) _beginthreadex(NULL, 
										NULL, 
										ThreadFunction, 
										this, 
										NULL, 
										(UINT *)&m_dwThreadID);

	if (m_hThread == INVALID_HANDLE_VALUE)
	{
		return FALSE;
	}

	return TRUE;
}

void CLoopThread::LoopProc()
{
	m_bRunThread = TRUE;

	while (m_bRunThread)
	{
		Process();

		Sleep(1);
	}
}

void CLoopThread::Process()
{
}

void CLoopThread::CloseThread()
{
	if (m_bRunThread == FALSE)	return;

	m_bRunThread = FALSE;

	WaitForSingleObject(m_hThread, INFINITE);
	CloseHandle(m_hThread);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -