I have a program that have a control thread and some connection threads. Then user stop connections though control thread, I hope control thread can stop connection threads and close CSocket, I write these line:

typedef struct _CONNECTION_THREAD
{
CSocket * connectionSocket;
CMyObject * myObject;
} CONNECTION_THREAD;

UINT controlThread(LPARAM lParam)
{
CONNECTION_THREAD connectThreadStruct;
CWinThread connectThread;
connectThread = ::AfxBeginThread(conntectFunction, &connectThreadStruct);

MSG msg;
while (TRUE)
{
::GetMessage(&msg, NULL, 0, 0);
switch (msg.message)
{
case WM_TIMER:
.
.
case WM_DISCONNECT:
::TerminateThread(connectThread.m_hThread, 0);
if (connectThreadStruct.connectSocket != NULL)
{
connectThreadStruct.connectSocket->Close();
delete connectThreadStruct.connectSocket;
connectThreadStruct.connectSocket = NULL
}
break;
.
.
.
}
}

UINT conntectFunction(LPARAM lParam)
{
CONNECT_THREAD* connectThreadStruct = (CONNECT_THREAD *)lParam;
connectThreadStruct->connectSocket = new CSocket();
connectThreadStruct->connectSocket->Create();
// begin to connect to server and logon and then receive some data... ...
// it can't get other message here
}

but it still have problem with CSocket's close function, I had try put TerminateThread after CSocket's close but still have problem. If I don't close it but only delete it, sometime it will failed then I create another CSocket, error code is 10055, that means "No buffer space is available. The socket cannot be created." I don't know if it because I haven't close some Socket before I delete it.
Who can tell me why? I know better not use TerminateThread, but I must control timeout and user stop here, so I must use it.
Thanks.