| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 921 人关注过本帖
标题:WaitForMultipleObjects函数的用法,为什么只会运行一次
只看楼主 加入收藏
bowengo
Rank: 2
等 级:论坛游民
帖 子:13
专家分:25
注 册:2010-5-23
结帖率:80%
收藏
已结贴  问题点数:10 回复次数:1 
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);
        }

    }


}
搜索更多相关主题的帖子: 函数 用法 运行 
2010-06-13 23:30
梦幻老妖
Rank: 1
等 级:新手上路
帖 子:2
专家分:7
注 册:2010-6-16
收藏
得分:7 
第三个参数改为TRUE,所有句柄被释放的时候才返回,FALSE为有一个句柄释放便返回。If this parameter is TRUE, the function returns when the state of all objects in the lpHandles array is signaled. If FALSE, the function returns when the state of any one of the objects is set to signaled.
2010-06-16 16:14
快速回复:WaitForMultipleObjects函数的用法,为什么只会运行一次
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011803 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved