|You are creating a user-interface thread. With socket operations worker threads are usual.
Also, why did you retry to create the thread if the first call fails? This makes no sense.
If the thread creation is done by your main thread, it will be blocked by calling
WaitForSingleObject() until the thread terminates.
The skeleton for using a worker thread would look like this:
static UINT ThreadFunc(LPVOID pParam);
m_pThread = AfxBeginThread(ThreadFunc, this, THREAD_PRIORITY_NORMAL,
UINT CMyClass::ThreadFunc(LPVOID pParam)
CMyClass* pThis = reinterpret_cast<CMyClass*>(pParam);
bool bKill = false;