引用 3 楼 ljdtj 的回复:
ce5.0不允许wait type设为true.这个你是从哪里知道的啊。
你提到的“线程1会不会继续等待WaitForSingleOb(hEvent[0],);”,这个我没在CE5.0上调试过,在桌面PC上是可行的,不会阻塞线程1,我试过了。你说的“从而不能及时退出循环”我就不太明白了,因为我的3个子线程本来就是死循环,我是定时到了之后ExitThread的。呵呵,这个方式不怎么好。
谢谢visualthinking。
[/quote]
可以查MSDN ,上面明确说明了fWaitAll必须为FALSE,如果设定为TRUE,系统则会自动设成FALSE或者出错。
fWaitAll
[in] Specifies the wait type. This parameter must be set to FALSE. This causes function to return when the state of any one of the objects set to is signaled. The return value indicates the object whose state caused the function to return.
这是可以的 ,一旦7个 event中有一个触发 WaitForMultipleObjects就会成功。
LZ是 要2个 都触发了 才WaitForMultipleObjects成功。WinCE下 并不能这么做。
可以参照下面这个。。MS社区上找的。
DWORD MyWaitForMultipleObjects(DWORD count, const HANDLE *lpHandles,
BOOL waitAll, DWORD ms)
{
#ifdef _WIN32_WCE
if (!waitAll)
return WaitForMultipleObjects(count, lpHandles, waitAll, ms);
else
{
// wait for each in turn. Note that this does not exactly simulate
// WaitForMultipleObjects, as each object will become signalled as
// soon as WaitForSingleObjects recognizes it, rather than all becoming
// signaled together as with WaitForMultipleObjects...
DWORD ret = WAIT_OBJECT_0;
for (DWORD n = 0;n < count;n++)
{
DWORD d;
d = WaitForSingleObject(lpHandles, ms);
if (WAIT_TIMEOUT == d)
{
ret = WAIT_TIMEOUT;
break;
}
else if (WAIT_ABANDONED == d)
{
ret = WAIT_ABANDONED_0 + n;
break;
}
}