C# waitformultipleobjects()
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 = 4; int[] m_iEvent = new int[4]; IntPtr pt = new IntPtr(); m_iEvent[0] = CreateEvent(pt, false, false, null); m_iEvent[1] = CreateEvent(pt, false, false, null); m_iEvent[2] = CreateEvent(pt, false, false, null); m_iEvent[3] = CreateEvent(pt, false, false, null); SetEvent(m_iEvent[2]); bool bOK = false; while (!bOK) { uint uiRet = 0xffff; uiRet = WaitForMultipleObjects(iMaxEventNum, ref m_iEvent[0], false, Timeout.Infinite); //uiRet 返回事件的index } } }
posted on 2015-11-12 09:42 strangeman 阅读(978) 评论(0) 编辑 收藏 举报