03EventDemo

 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 }

 

posted @ 2017-02-01 22:58  泛未分晨  阅读(173)  评论(0编辑  收藏  举报