在每发一个字符串后加个适当的延时吧,或者来个application.doevents

解决方案 »

  1.   

    public void StartServer()
    {
    if(!m_Running){
    m_Running = true; Thread tr = new Thread(new ThreadStart(this.StartProcCons));
    tr.Start();
    Thread trSessionCreator = new Thread(new ThreadStart(this.StartProcQueuedCons));
    trSessionCreator.Start(); m_pTimer.Enabled = true;
    }
    }
    private void StartProcCons()
    {
    try{
    m_pListner = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
    m_pListner.Bind(m_pIPEndPoint);
    m_pListner.Listen(500);


    while(m_Running){

    if(m_pSessions.Count > m_MaxConnections){

    while(m_pSessions.Count > m_MaxConnections){
    Thread.Sleep(100);
    }
    }
    Socket s = m_pListner.Accept();
    lock(m_pQueuedConnections){
    m_pQueuedConnections.Add(s);
    }
    }
    }
    catch(SocketException x){

    if(x.ErrorCode == 10004){
    }
    else{
    OnSysError("WE MUST NEVER REACH HERE !!! StartProcCons:",x);
    }
    }
    catch(Exception x){
    OnSysError("WE MUST NEVER REACH HERE !!! StartProcCons:",x);
    }
    }
    试试阻塞模式