TerminateThread

  BOOL TerminateThread(hThread, dwExitCode)    
  HANDLE hThread;    
  DWORD dwExitCode;    

A thread may be terminated using TerminateThread.

Parameters

hThread

Supplies a handle to the thread to terminate. The handle must have been created with THREAD_TERMINATE access.

dwExitCode

Supplies the termination status for the thread.

Return Value

The return value is TRUE if the function is successful. Otherwise, it is FALSE in which case extended error information is available from the GetLastError function.

TerminateThread is used to cause a thread to terminate user-mode execution. There is nothing a thread can do to predict or prevent when this occurs. If a process has a handle with appropriate termination access to the thread or to the threads process, then the thread can be unconditionally terminated without notice. When this occurs, the target thread has no chance to execute any user-mode code and its initial stack is not deallocated. The thread attains a state of signaled satisfying any waits on the thread. The thread's termination status is updated from its initial value of STATUS_PENDING to the value of the TerminationStatus parameter. Terminating a thread does not remove a thread from the system. The thread is not removed from the system until the last handle to the thread is closed.

See Also

ExitThread