首页 > 代码库 > 03EventDemo
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 }
03EventDemo
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。