[Quote=引用 14 楼 soyokaze 的回复:]
我想的是零等待判断线程是否结束,而不是死等。
其实可以用一个事件来实现,线程退出时设置事件为有信号,就可以判断已经退出了。
但是我想的是用 WaitForSingleObject()这种直接的方法。
按照MSDN文档,本来是可以的,但是出现了0楼所述的问题,这贴的目的是问这个的。
[/Quote]
你判断线程结束的方法用的是GetExitCodeThread,通过它的返回值来判断的,但是MSDN上对GetExitCodeThread的返回值的说法是:
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero
GetExitCodeThread返回0只是说明这个函数调用失败,并不是说线程已经退出了。
用GetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode)
判断线程状态是看它的第二个参数 lpExitCode是不是STILL_ACTIVE吧。
引用 4 楼 fishion 的回复:
WaitForSingleObject(hThread, 0);
If dwMilliseconds is zero, the function tests the object's state and returns immediately
所以用WaitForSingleObject(hThread, INFINITE);
[Quote=引用 4 楼 fishion 的回复:]
WaitForSingleObject(hThread, 0);
If dwMilliseconds is zero, the function tests the object's state and returns immediately
所以用WaitForSingleObject(hThread, INFINITE);
[/Quote]
我估计楼主并不想等待线程结束,他的目的是判断线程是否结束,而不是想等待它结束。
[Quote=引用 4 楼 fishion 的回复:]
WaitForSingleObject(hThread, 0);
If dwMilliseconds is zero, the function tests the object's state and returns immediately
所以用WaitForSingleObject(hThread, INFINITE);
[/Quote]正解
WaitForSingleObject(hThread, 0);
If dwMilliseconds is zero, the function tests the object's state and returns immediately
所以用WaitForSingleObject(hThread, INFINITE);