Use mandatory means to end a process

Source: Internet
Author: User

VOID ExitThread (

DWORD Dwexitcode);

Dwexitcode Specify this thread end code

No return value

This function is somewhat like the exit () function in the C runtime library because he can be called at any time and will never return. Any code that is placed below this line is guaranteed not to be executed.

#define Win32_lean_and_mean#include <stdlib.h> #include <stdio.h> #include <windows.h>dword WINAPI ThreadFunc (LPVOID); void Anotherfunc (void); int main () {HANDLE Hthrd;dword ExitCode = 0;dword THREADID;HTHRD = CreateThread (Null,0,threadfunc, (LPVOID) 1,0,&threadid); if (HTHRD) {printf ("Thread launched\n");} for (;;) {BOOL RC;RC = GetExitCodeThread (Hthrd,&exitcode); if (rc && exitCode! = still_active) break;} CloseHandle (HTHRD);p rintf ("Thread returned%d\n", ExitCode); return exit_success;} DWORD WINAPI ThreadFunc (lpvoid N) {  printf ("Thread running\n"); Anotherfunc (); return 0;} void Anotherfunc () {printf ("About to exit thread\n"); ExitThread (4);p rintf ("This would never printf\n");}


The thread that is executed after the thread is started is called the main threads (primary thread). Main thread two features. First, he is responsible for the logoff information loop in the GUI (Graphic User Interface) program. Second, the end of this thread (either because it is returned or because the call to ExitThread ()) causes all threads in the program to be forced to end, and the program ends. Other threads do not have the opportunity to do cleanup work.

Use mandatory means to end a process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.