本帖最后由 stlnkm 于 2010-05-22 00:06:14 编辑

解决方案 »

  1.   


    不是退出,我是通过设置bool变量让它退出的。
      

  2.   

    下面是我的发送线程源码
    //发送屏幕图像块线程
    UINT __cdecl CScreenMonitor::SenderThread(LPVOID lpParameter)
    {
    //处理线程参数
    LPMONITORTHREADPARAM pParam=(LPMONITORTHREADPARAM)lpParameter;
    CScreenMonitor* pThis=pParam->pThis;
    SOCKET hSocket=(SOCKET)pParam->dwData;
    delete pParam; CSocketEx SenderSocket(OnProcessNetMsg);
    SenderSocket.Attach(hSocket); CHead Head;
    Head.m_nRowCount=m_ScreenMonitor.m_nMonitorThreadNum;
    Head.m_nColCount=m_ScreenMonitor.m_nBlockNumPerThread;
    Head.m_nCXScreen=pThis->m_nCXScreen;
    Head.m_nCYScreen=pThis->m_nCYScreen;
    SenderSocket.SendData(&Head); //CSafeBlock* pSendedData=NULL;
    CBlock* pBlock=NULL;
    while(!m_ScreenMonitor.m_bEndService)
    {
    //if(m_ScreenMonitor.m_lFinishCount==m_ScreenMonitor.m_nMonitorThreadNum)
    if(::InterlockedExchange(&m_ScreenMonitor.m_lFinishCount,m_ScreenMonitor.m_lFinishCount)==m_ScreenMonitor.m_nMonitorThreadNum)
    {
    m_ScreenMonitor.m_lFinishCount=(LONG)0;
    while(!m_ScreenMonitor.m_pSendedData.IsEmpty())
    {
    //pThis->m_sbListLock.Lock();
    pBlock=m_ScreenMonitor.m_pSendedData.RemoveHead();
    //pThis->m_sbListLock.Unlock(); if(m_ScreenMonitor.m_pSendedData.IsEmpty())//最后一块
    {
    pBlock->m_bLastBlock=true;
    } SenderSocket.SendData(pBlock); //::SetEvent(pSendedData->m_hEvent);
    }
    BOOL b;
    for(int i=0;i<m_ScreenMonitor.m_nMonitorThreadNum;++i)
    {
    b=::SetEvent(m_ScreenMonitor.m_phThreadEvents[i]);
    }
    }
    Sleep(300);
    }
    return 0;
    }
    发送的数据量比较多
      

  3.   

    补充:SenderSocket.SendData(pBlock);的SendData中使用了CSocketFile和CArchive发送数据