線程SuspendThread() ResumeThread()的使用

SuspendThread():掛起線程 If the function succeeds, the return value is the thread's previous suspend count; otherwise, it is (DWORD) -1.this

ResumeThread():啓動線程  If the function succeeds, the return value is the thread's previous suspend count; otherwise, it is (DWORD) -1..net

If the return value is zero, the specified thread was not suspended. If the return value is 1, the specified thread was suspended but was restarted.線程

If the return value is greater than 1, the specified thread is still suspended.rest

在知足條件時啓動線程,不知足條件時掛起線程blog

CWinThread *pthread;
建立線程
pthread=AfxBeginThread(ThreadProc,(LPVOID)this,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED,NULL)
if(condition)
{
        DWORD r=pthread->ResumeThread();
        if(r==-1)
            "啓動線程失敗"
}
else
{//掛起線程
        DWORD suspendcount=pthread->SuspendThread();
        if(suspendcount==-1)
             "掛起線程失敗"
        else
        {
                for (DWORD i = 0; i < suspendcount; i++)//若是掛起屢次,須要啓動多餘掛起的次數,保證只掛起一次,不然知足條件時線程並不能啓動
                {
                     pthread->ResumeThread();
                 }
        }
}ci

————————————————
版權聲明:本文爲CSDN博主「long龍兒er」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處連接及本聲明。
原文連接:https://blog.csdn.net/u010439291/article/details/54562689it

相關文章
相關標籤/搜索