码迷,mamicode.com
首页 > 其他好文 > 详细

03EventDemo

时间:2017-02-01 23:41:09      阅读:378      评论:0      收藏:0      [点我收藏+]

标签:param   seh   blog   getchar   sig   demo   system   creat   thread   

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<process.h>
 4 #include<windows.h>
 5 
 6 HANDLE g_hEvent;
 7 UINT __stdcall ThreadProc(LPVOID);
 8 int main(int argc,char* argv[])
 9 {
10     unsigned uThreadId;
11     char szEventName[] = "MyEvent";
12     HANDLE hThread = (HANDLE)::_beginthreadex(NULL,0,ThreadProc,NULL,0,&uThreadId);
13     g_hEvent = ::CreateEvent(NULL,false,false,szEventName);
14     printf("Input something to go on!\n");
15     getchar();
16     ::SetEvent(g_hEvent);
17     ::WaitForSingleObject(hThread,INFINITE);
18     printf("The Thread has been finished all works!\n");
19     ::CloseHandle(g_hEvent);
20     ::CloseHandle(hThread);
21     
22     system("pause");
23     return 0;
24 }
25 UINT __stdcall ThreadProc(LPVOID lpParam)
26 {
27     ::WaitForSingleObject(g_hEvent,INFINITE);
28     printf("Thread are runing!\n");
29     Sleep(2000);
30     return 0;
31 }

 

03EventDemo

标签:param   seh   blog   getchar   sig   demo   system   creat   thread   

原文地址:http://www.cnblogs.com/FWFC/p/6360483.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!