TerminateThread

Prototypes

BOOL TerminateThread(HANDLE Handle, DWORD CodeRetour);

Description

Termine le thread identifié par le handle Handle avec le code retour CodeRetour.

Un thread se termine normalement par l'instruction return au sein de sa fonction principale.

Exemple

#include <windows.h>
#include <winbase.h>

SECURITY_ATTRIBUTES AttributDeSecurites;
HANDLE Handle;
DWORD NumeroThread;

static DWORD WINAPI PrincipalThread(LPVOID Parametres)
{
...
return(0);
}

...
AttributDeSecurites.nLength=sizeof(SECURITY_ATTRIBUTES);
AttributDeSecurites.bInheritHandle=TRUE;
AttributDeSecurites.lpSecurityDescriptor=NULL;
Handle=CreateThread(&AttributDeSecurites, 0, PrincipalThread, (PVOID)"Bonjour le monde", 0, &NumeroThread);
if (!Handle) ...
if (!TerminateThread(Handle, 0)) ...

Avertissement

Bien s'assurer que le handle identifie un thread s'exécutant.

Si le thread n'a pu être créé, le résultat est Faux.

Voir aussi

CreateThread pour créer un nouveau thread. GetCurrentThread pour retrouver le handle du thread courant. GetCurrentThreadId pour retrouver l'identifiant du thread courant. GetExitCodeThread pour lire le code retour d'un thread.