views:

60

answers:

1

Here it is

  1. Create a thread in suspended state.

    hThrd1 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) ThreadProc1, (LPVOID)
    &obj1, CREATE_SUSPENDED, &dwFirstThreadID);
    
  2. 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 called

    SuspendThread(hThrd1);

Still the for loop in the ThreadProc keeps running. Now how do I avoid it? Also suggest me for any alternatives.

+1  A: 

I got the problem. Initially thread HANDLE hThrd1 was declared inside WndProc. Since WndProc keeps calling 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.

Thanks to Alex and those who viewed this quetion.

AKN