The TerminateThread function terminates a thread. It is a relatively drastic way to stop a thread and should be used with caution.
BOOL TerminateThread(
_In_ HANDLE hThread,
_In_ DWORD dwExitCode
);
hThread
[in]THREAD_TERMINATE
access right.
dwExitCode
[in]If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError.
The TerminateThread function is used to terminate a thread. It is important to understand the implications of terminating a thread abruptly. When a thread is terminated, the following occurs:
If the terminated thread was the primary thread of a process, all other threads in the process are terminated as well. The system does not perform any special cleanup for other threads. For this reason, TerminateThread should only be called when the calling application has no other way to stop the thread.
It is generally recommended to use other mechanisms for thread termination, such as signaling events or setting flags that the thread periodically checks to exit gracefully.
The dwExitCode
parameter specifies the thread's exit status.
Typically, an exit code of 0 indicates successful termination, while a non-zero value indicates an error.
The value STILL_ACTIVE
(defined as 259) indicates that the thread is still running.