?? threadjob.cpp
字號:
// ThreadJob.cpp: implementation of the CThreadJob class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "RTMS.h"
#include "ThreadJob.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNAMIC(CThreadJob, CObject)
CThreadJob::CThreadJob()
{
m_pThread = NULL;
}
CThreadJob::~CThreadJob()
{
if (m_pThread) {
TRACE("CThreadJob: *** Warning: deleting active thread! ***\n");
delete m_pThread;
}
}
UINT CThreadJob::ThreadProc(LPVOID pObj)
{
CThreadJob* pJob = (CThreadJob*)pObj;
ASSERT_KINDOF(CThreadJob, pJob);
pJob->m_uErr = pJob->DoWork(); // call virt fn to do the work
return pJob->m_uErr; // ..and return error code to Windows
}
BOOL CThreadJob::Begin(CWnd* pWndOwner, UINT ucbMsg)
{
m_hWndOwner = pWndOwner->GetSafeHwnd();
m_ucbMsg = ucbMsg;
m_bAbort = FALSE;
m_uErr = 0;
m_pThread = AfxBeginThread(ThreadProc,
(LPVOID)this,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
ASSERT(m_pThread);
m_pThread->m_bAutoDelete = FALSE;
m_pThread->ResumeThread();
return m_pThread != NULL;
}
void CThreadJob::Abort(BOOL bAbort)
{
m_bAbort = bAbort;
}
void CThreadJob::OnProgress(WPARAM wp, LPARAM lp)
{
if (m_hWndOwner && m_ucbMsg)
::PostMessage(m_hWndOwner, m_ucbMsg, wp, lp);
}
BOOL CThreadJob::IsNormalQuit()
{
int rc;
try
{
rc = ::WaitForSingleObject(m_pThread->m_hThread,0);
if( WAIT_OBJECT_0 == rc )
{
delete m_pThread;
m_pThread = NULL;
return TRUE; //線程正常結束
}
}
catch(...){return TRUE;} //線程異常結束
return FALSE; //線程未結束
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -