ResumeThread

The ResumeThread function resumes the execution of a suspended thread. If the thread is not suspended, this function has no effect.

Syntax

DWORD ResumeThread(
      HANDLE hThread
    );
            

Parameters

Parameter Type Description
hThread HANDLE A handle to the thread to be resumed. This 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 successful call to ResumeThread decrements the thread's suspend count. The thread's execution is resumed only when its suspend count reaches zero.

A thread's suspend count is incremented each time the SuspendThread function is called.

If the thread specified by hThread was created by a call to the CreateProcess function, the system has already suspended the process's primary thread. To resume the primary thread, you must call ResumeThread once for the process's primary thread before calling CreateProcess.

Important: Be cautious when resuming threads. Improper use can lead to race conditions or deadlocks. Ensure you understand the thread's current state before calling ResumeThread.

Example


#include <windows.h>
#include <iostream>

int main() {
    // Assume hThread is a valid handle to a suspended thread
    HANDLE hThread = ...; // Obtain a handle to a suspended thread

    DWORD previousSuspendCount = ResumeThread(hThread);

    if (previousSuspendCount == (DWORD)-1) {
        // Handle error
        std::cerr << "Error resuming thread: " << GetLastError() << std::endl;
    } else {
        std::cout << "Thread resumed. Previous suspend count: " << previousSuspendCount << std::endl;
        if (previousSuspendCount == 1) {
            std::cout << "Thread is now running." << std::endl;
        }
    }

    // Close the thread handle when done
    CloseHandle(hThread);

    return 0;
}
            

Requirements

| |
Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server
Header
winbase.h
Library
Kernel32.lib
DLL
Kernel32.dll