📄 thread.h
字号:
#ifndef _M_THREAD_2004_7_28_ZHY_H
#define _M_THREAD_2004_7_28_ZHY_H
#include <afxmt.h>
#include "../include/exception.h"
using namespace CommonInclude;
namespace ThreadLib{
class ThreadBase
{
public:
////////////////////////////////////////////////////////////////////////////
// Constructors / Destructor //
////////////////////////////////////////////////////////////////////////////
// Constructor
ThreadBase(void);
// Desturctor
virtual ~ThreadBase();
// Priority is the same with MFC
enum THREAD_PRIORITY
{
PRIORITY_HIGHEST = 7,
PRIORITY_ABOVE_NORMAL = 1,
PRIORITY_NORMAL = 0,
PRIORITY_BELOW_NORMAL = -1,
PRIORITY_LOWEST = -7,
};
protected:
////////////////////////////////////////////////////////////////////////////
// Implemetation //
////////////////////////////////////////////////////////////////////////////
typedef unsigned (__stdcall * ThreadFunc)(void * arg);
static int Start(ThreadFunc func,void * arg,int nStackSize,int nPrio);
void * m_thread;
unsigned int m_threadID;
};
class Thread : public ThreadBase
{
public:
////////////////////////////////////////////////////////////////////////////
// Constructors / Destructor //
////////////////////////////////////////////////////////////////////////////
// Constructor
Thread();
// Destructor
virtual ~Thread(void);
////////////////////////////////////////////////////////////////////////////
// Inline Set/Get Operations //
////////////////////////////////////////////////////////////////////////////
inline unsigned int GetThreadID() const { return m_threadID; }
inline int GetThreadResult() const { return m_nThreadResult; }
////////////////////////////////////////////////////////////////////////////
// Operations //
////////////////////////////////////////////////////////////////////////////
void StartEx(int nStackSize = 64 * 1024,int nPriority = ThreadBase::PRIORITY_NORMAL) throw(CExceptionBase);
// Stop the thread
void Stop();
int StopEx();
protected:
////////////////////////////////////////////////////////////////////////////
// Implemetation //
////////////////////////////////////////////////////////////////////////////
virtual int Run() = 0;
virtual void OnDelete(){}
virtual void OnException(CException& e) {}
int WaitUntilStop();
private:
static unsigned __stdcall ThreadProxy(void * arg);
int m_nThreadResult;
bool m_bWantExit;
CEvent m_evHasExit;
};
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -