To perform a specific task, I had to resort to creating an additional stream. I create a new thread in a windowed application.
D. Richter recommends using the _beginthreadex() and _endthreadex() functions
HANDLE hThread; unsigned threadID; hThread = (HANDLE)_beginthreadex(NULL, 0, &ThreadFunc, NULL, 0, &threadID); WaitForSingleObject(hThread, INFINITE); CloseHandle(hThread); stream function:
unsigned __stdcall ThreadFunc(void* pArguments) { while(true) { //... } _endthreadex(0); return 0; } As a result, the thread is started, its code is executed, and the WaitForSingleObject function waits for it to finish, in order to close its handles later.
The problem is that this WaitForSingleObject hangs the window itself. Question: if you remove WaitForSingleObject and CloseHandle(hThread) from the code, how else should you wait for the thread to close in order to close its handle without hanging the main program?