ResumeThread
Header
#include <processthreadsapi.h>
Syntax
DWORD ResumeThread(
HANDLE hThread
);
Parameters
| Parameter | Description |
|---|---|
hThread | Handle to the thread to be resumed. The handle must have the THREAD_SUSPEND_RESUME access right. |
Return value
If the function succeeds, the return value is the thread's previous suspend count. If the function fails, the return value is (DWORD)-1. To get extended error information, call GetLastError.
Remarks
- Each call to
SuspendThreadincrements a thread's suspend count.ResumeThreaddecrements this count. The thread runs only when the suspend count reaches zero. - Do not call
ResumeThreadon a thread that is not suspended; doing so can cause unexpected behavior. - If the thread was created with the
CREATE_SUSPENDEDflag, a single call toResumeThreadwill start execution.
Example
#include <windows.h>
#include <stdio.h>
DWORD WINAPI ThreadProc(LPVOID lpParameter) {
for (int i = 0; i < 5; ++i) {
printf("Thread running: %d\n", i);
Sleep(500);
}
return 0;
}
int main(void) {
HANDLE hThread = CreateThread(
NULL, // default security attributes
0, // default stack size
ThreadProc, // thread function
NULL, // parameter to thread function
CREATE_SUSPENDED, // start suspended
NULL); // thread identifier
if (hThread == NULL) {
printf("CreateThread failed (%lu)\n", GetLastError());
return 1;
}
printf("Thread created suspended. Resuming...\n");
if (ResumeThread(hThread) == (DWORD)-1) {
printf("ResumeThread failed (%lu)\n", GetLastError());
}
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
return 0;
}