Microsoft Docs ResumeThread

ResumeThread

Header

#include <processthreadsapi.h>

Syntax

DWORD ResumeThread(
    HANDLE hThread
);

Parameters

ParameterDescription
hThreadHandle 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

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;
}

See Also