VC program in a good way to exit the thread, is to review the event

Source: Internet
Author: User


Direct look at the program:

1. Initialize the place to create "Exit event"
HANDLE exitevent =:: CreateEvent (null,false,false,null);


2. The following is placed on a line Chengri while
(1)
{
	//constant detection event is triggered. Otherwise 1ms timeout (equivalent to sleep (1))
	DWORD st =:: WaitForSingleObject (Exitevent, 1);//1ms wait
	if (st = = wait_object_0)
	{ Break
		;	Exit line Chengri Loop
	}

	//deal with the right thing to do.
	//.................
	//.................
}

3. The other position in the program signals, triggering "Exit event"
SetEvent (exitevent);


Of course, the event variables mentioned above are no different from the exit flags for a Boolean type of global variable.




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.