class WatchThread
{
[DllImport("kernel32.dll")]
private static extern int CreateEvent(IntPtr lpEventAttributes,
bool bManualReset,
bool bInitialState,
string lpName); [DllImport("kernel32.dll")]
private static extern bool SetEvent(int iEvent); [DllImport("kernel32.dll")]
private static extern uint WaitForMultipleObjects(uint nCount,
ref int lpHandles,
bool bWaitAll,
int dwMilliseconds); public void Test()
{
const uint iMaxEventNum = ; int[] m_iEvent = new int[];
IntPtr pt = new IntPtr(); m_iEvent[] = CreateEvent(pt, false, false, null);
m_iEvent[] = CreateEvent(pt, false, false, null);
m_iEvent[] = CreateEvent(pt, false, false, null);
m_iEvent[] = CreateEvent(pt, false, false, null);
SetEvent(m_iEvent[]);
bool bOK = false;
while (!bOK)
{
uint uiRet = 0xffff;
uiRet = WaitForMultipleObjects(iMaxEventNum, ref m_iEvent[], false, Timeout.Infinite);
//uiRet 返回事件的index
}
}
}

C# waitformultipleobjects()的更多相关文章

  1. WaitForMultipleObjects返回失败原因之一

    上网搜了下 关于 WaitForMultipleObjects等待多个线程退出的状态失败的情况,也有人遇到类似的情况. 一次项目中我也遇到这么个情况.项目中创建线程都是用的  _beginthread ...

  2. WaitForSingleObject 和 WaitForMultipleObjects函数

    1.WaitForSingleObject 等待函数可使线程自愿进入等待状态,直到一个特定的内核对象变为已通知状态为止.这些等待函数中最常用的是WaitForSingleObject:   DWORD ...

  3. WaitForSingleObject与WaitForMultipleObjects用法详解(好用,而且进入一个非常高效沉睡状态,只占用极少的CPU时间片)

    在多线程下面,有时候会希望等待某一线程完成了再继续做其他事情,要实现这个目的,可以使用Windows API函数WaitForSingleObject,或者WaitForMultipleObjects ...

  4. delphi 中使用WaitForMultipleObjects等待线程执行,再执行后续代码

    unit1 [delphi] view plain copyunit Unit1; interface uses Windows, Messages, SysUtils, Variants, Clas ...

  5. dephi WaitForMultipleObjects 用法

    在Delphi中WaitForMultipleObjects的使用   procedure ThreadTest;stdcall; var Handles:TWOHandleArray; //Hand ...

  6. WaitForMultipleObjects返回0xffffffff

    DWORD ret; ; HANDLE handle[THREAD_NUM]; ; i < THREAD_NUM; i++) handle[i] = (HANDLE)_beginthreadex ...

  7. WaitForMultipleObjects

    WaitForMultipleObjects是Windows中的一个功能非常强大的函数,几乎可以等待Windows中的所有的内核对象 函数原型为: DWORD WaitForMultipleObjec ...

  8. WaitForMultipleObjects用法详解

    本文转载于:http://blog.csdn.net/sac761/article/details/52456385 WaitForMultipleObjects是Windows中的一个功能非常强大的 ...

  9. 【VS开发】WaitForSingleObject 和 WaitForMultipleObjects函数 (让线程挂起等待事件)

    WaitForSingleObject 和 WaitForMultipleObjects:1.WaitForSingleObject  等待函数可使线程自愿进入等待状态,直到一个特定的内核对象变为已通 ...

随机推荐

  1. 《用C++语言编写一个程序,求PI的值》

    //编写一个C++程序求PI的值 /* PI=16arctan(1/5)-4arctan(1/239) 其中arctan用如下形式的极数计算: arctan=x-(x^3/3)+(x^5/7)-(x^ ...

  2. poj2891 拓展欧几里得

    //Accepted 164 KB 16 ms //拓展欧几里得 //m=a1*x+b1 --(1) //m=a2*(-y)+b2 --(2) //->a1*x+a2*y=b2-b1 //由欧几 ...

  3. C# 跨线程操作控件(简洁)

                                              C# 跨线程操作控件 .net 原则上禁止跨线程访问控件,因为这样可能造成错误的发生.解决此问题的方法有两个: 第一 ...

  4. LeetCode222 Count Complete Tree Nodes

    对于一般的二叉树,统计节点数目遍历一遍就可以了,但是这样时间复杂度O(n),一下就被卡住了. 这题首先要明白的是,我们只需要知道叶子节点的数目就能统计出总节点树. 想法1: 既然是完全二叉树,我肯定是 ...

  5. Reachability判断网络是否连接

    类似于一个网络状况的探针. [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabili ...

  6. Java容器类List,ArrayList及LinkedList

    List容器类图 List是一个接口,它继承自Collection和Iterable,它的实现类有AbstractList,AbstrackSequenceList,ArrayList,LinkedL ...

  7. Android 编译Settings、Mms等模块,并Push到手机中安装失败

    问题描述:在编译完Settings等相关模块后,并push到手机中安装失败(在手机中无法找到该应用),但是使用adb shell命令进入到手机中在System/app或者System/priv-app ...

  8. css3 绘制优惠券

    今天偶然发现了一个css3制作动画的地方,发现css3的径向渐变好难理解,幸亏有这里的大神介绍http://www.daqianduan.com/5989.html,这是优惠券的介绍 还有这个http ...

  9. 【LeetCode OJ】Gas Station

    Problem link: http://oj.leetcode.com/problems/gas-station/ We can solve this problem by following al ...

  10. codeforces 711C Coloring Trees(DP)

    题目链接:http://codeforces.com/problemset/problem/711/C O(n^4)的复杂度,以为会超时的 思路:dp[i][j][k]表示第i棵数用颜色k涂完后bea ...