Multithreading visualc&x2B+;函数没有看到线程终止
我的表单的onClick事件函数中有以下代码:Multithreading visualc&x2B+;函数没有看到线程终止,multithreading,visual-studio-2010,visual-c++,Multithreading,Visual Studio 2010,Visual C++,我的表单的onClick事件函数中有以下代码: HANDLE hThread; unsigned threadID; output->Text = "Starting"; _beginthreadex( NULL, 0, &start, NULL, 0, &threadID ); DWORD dwRes = WaitForSingleObject( hThread, INFINITE ); if (dwRes == WAIT_OBJECT_0 || dwRes == W
HANDLE hThread;
unsigned threadID;
output->Text = "Starting";
_beginthreadex( NULL, 0, &start, NULL, 0, &threadID );
DWORD dwRes = WaitForSingleObject( hThread, INFINITE );
if (dwRes == WAIT_OBJECT_0 || dwRes == WAIT_ABANDONED || dwRes == WAIT_TIMEOUT){
CloseHandle( hThread );
output->Text = "Done";
}
函数start
返回0
无论发生什么情况。我看到output
标签更改为“start”,但它从未更改为“Done”。但是,我在Visual Studio输出窗口中看到以下消息:
The thread 'Win32 Thread' (0x2dc) has exited with code 0 (0x0).
The thread '<No Name>' (0x2dc) has exited with code 0 (0x0).
线程“Win32线程”(0x2dc)已退出,代码为0(0x0)。
线程“”(0x2dc)已退出,代码为0(0x0)。
我不知道为什么
if
语句没有捕捉到线程的末尾。是否有任何函数可以与线程句柄一起使用来探测线程的状态 您尚未将线程句柄分配给hThread
应该是:
hThread = _beginthreadex( NULL, 0, &start, NULL, 0, &threadID );