How to suspend a running thread using win32 api's?
Here it is
Create a thread in suspended state.
hThrd1 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) ThreadProc1, (LPVOID) &obj1, CREATE_SUSPENDED, &dwFirstThreadID);
Resume the thread whenever required
ResumeThread(hThrd1);
How do I suspend this running thread. I may resume it after sometime, but I want to suspend it now.
I 开发者_JS百科called
SuspendThread(hThrd1);
Still the for loop in the ThreadProc keeps running. Now how do I avoid it? Also suggest me for any alternatives.
I got the problem. Initially thread HANDLE hThrd1 was declared inside WndProc. Since WndProc is being called again & again, the HANDLE that I got during CreateThread was not the same that was passed to suspend thread. (It was an embarrassing mistake)
Now I have declared it globally. This solves the problem and works as intended.
精彩评论