WaitForMultipleObjects函数的用法,为什么只会运行一次
#include "stdio.h"#include "process.h"
#include "windows.h"
HANDLE gEvent[2];
void main()
{
int i;
DWORD dwEvent;
for (i = 0; i < 2; i++)
{
gEvent[i] = CreateEvent(
NULL,
FALSE,
TRUE,
NULL);
if (gEvent[i] == NULL)
{
printf("Create event failed.");
return;
}
}
while (1) {
dwEvent = WaitForMultipleObjects(
2,
gEvent,
FALSE,
INFINITE);
ResetEvent(gEvent[dwEvent - WAIT_OBJECT_0]);
switch (dwEvent)
{
case WAIT_OBJECT_0:
printf("Event1 signaled.\n");
break;
case WAIT_OBJECT_0 + 1:
printf("Event2 singnaled.\n");
break;
default:
printf("error occured.\n");
ExitProcess(0);
}
}
}