C++ 線程的創建

 

unsigned int WINAPI  ThreadProc(LPVOID pParam)
{
    CString s;
    for (int i = 0; i < 100; i++)
    {
        s.Format(L"Loop %d finished\r\n", i);
        OutputDebugString(s);
    }        
    return 0;   
}


void OnBnClickedButton()
{
    unsigned int id;
    HANDLE handle = (HANDLE)::_beginthreadex(0, 0, ThreadProc, (void*)this, 0, &id);

    /*等待線程退出*/
    /*
    DWORD dRet = WaitForSingleObject(handle, INFINITE);
    if (dRet == WAIT_OBJECT_0)
    {
        //線程結束
    }
    */

}


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章