1 #include2 #include 3 #include 4 #include 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 }