スレッド

static CWinThread* s_thread1 = NULL;

UINT thread1(LPVOID /*param*/)
{
test1();

return 0;
}

bool startThread()
{
if(s_thread1) return false;

const DWORD dwCreateFlags = CREATE_SUSPENDED;// OFF

s_thread1 = ::AfxBeginThread(thread1, NULL, THREAD_PRIORITY_NORMAL, 0, dwCreateFlags);
if(!s_thread1) return false;

s_thread1->m_bAutoDelete = FALSE;// 手動削除

s_thread1->ResumeThread();// ON

return true;
}

bool waitEndThread()
{
if(!s_thread1) return false;

CWaitCursor wait_cursor;

// 終了待ち
const bool b =(::WaitForSingleObject(s_thread1->m_hThread, INFINITE) == WAIT_OBJECT_0) ? true : false;

// ※不要。これ呼んだらエラーが出る
//::CloseHandle(s_thread1->m_hThread);

delete s_thread1;// 削除

s_thread1 = NULL;

return b;
}
最終更新:2011年12月22日 14:43
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。