ok, i am developing a TCP/IP Client-Server application. Im currently working on transferring multiple files simultaneously from Server to Client.

Here is the code that receives data

Code:
//Global variable
	struct SepComm 
	{
	      char UnmanagedData[8192];
	      int TotalSize;
	      int Sock;
	      void* param;
	};
Code:
case FD_READ:
{
	int SizeOfData = 0;
	int SockNO=0;

	for(SockNO=0;SockNO<=TotalConn;SockNO++)
	{
	          if (pMsg->wParam == sTemp[SockNO])
			break;
	}

         ZeroMemory(SepCommParam.UnmanagedData,sizeof(SepCommParam.UnmanagedData));
         SizeOfData=recv(sTemp[SockNO],(char*)SepCommParam.UnmanagedData,sizeof(SepCommParam.UnmanagedData)/sizeof(SepCommParam.UnmanagedData[0]),0);

	if(SizeOfData == -1)
		goto Close_Sock;

	if(SizeOfData != -1)
		if(SizeOfData != 0)
		{
			SepCommParam.TotalSize = SizeOfData;
			SepCommParam.Sock = SockNO;
			SepCommParam.param = this;
			DWORD threadID;
			HANDLE hThread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)SeparateCommands, &SepCommParam, 0, &threadID);
		}
					
}
break;
the problem is (if you haven't noticed it already) that before the thread (SeparateCommands) is completed , a new data is arrived and it changes the SepComm variables and crashes the function.

whats is the best what to prevent or fix this issue?

thanks