// TestWaitForSingleObject1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <iostream.h>
HANDLE hEvent;
DWORD WINAPI SampleThread(LPVOID iValue)
{
int iFinish = 10000;
for(int i=100;i<=iFinish;i++)
cout<<i<<endl;
SetEvent(hEvent);
return 0;
}
void main()
{
HANDLE hThread;
DWORD dwGenericThread;
hThread = CreateThread(NULL,0,SampleThread,NULL,0,&dwGenericThread);
if(hThread == NULL)
{
DWORD dwError = GetLastError();
cout<<"SCM:Error in Creating thread"<<dwError<<endl ;
return;
}
hEvent = CreateEvent(NULL,FALSE,FALSE,"Test");
cout<< "Started waiting for the thread to complete.." <<endl ;
//WaitForSingleObject(hEvent,INFINITE);
WaitForSingleObject(hEvent,100);
cout<<"Thread Completed."<<endl ;
if(hEvent != INVALID_HANDLE_VALUE)
CloseHandle(hEvent);
}
WaitForSingleObject의 2번째 인자를 바꾸어 보면 조금씩 다른 결과가 나온다..
가끔은 에러도 나는데;;; 이유는 잘 모르겠다
