日期:2014-05-20  浏览次数:20749 次

关于线程的初级问题.
我希望当监听到新的链接消息后.增加客户数量.并反应到label标签中.
现在出现如下问题:
请求解决方案


                private   void   OpenServer()
                {
                        //开始监听
                        MyTcpListener   =   new   TcpListener(m_ipServerIP,   m_iPort);
                        MyTcpListener.Start();

                        //创建监听线程
                        m_trdServer   =   new   Thread(new   ThreadStart(ListenRun));
                        //启动线程
                        m_trdServer.Start();

                        bnServer.Text   =   "Close ";
                        bServer   =   true;
                }

             
                /*
                  *   labClientCnt是   label控件
                  *   //创建监听线程
                        m_trdServer   =   new   Thread(new   ThreadStart(ListenRun));
                        //启动线程
                        m_trdServer.Start();
                  *   */
                private   void   ListenRun()
                {
                        while   (bThread)
                        {
                                Socket   s   =   MyTcpListener.AcceptSocket();

                                SClient   tSClient   =   new   SClient(s,   m_altClients.Count);

                                m_altClients.Add(tSClient);

                                /*下面语句产生错误
                                  *   Cross-thread   operation   not   valid:  
                                  *   Control   'labClientCnt '   accessed  
                                  *   from   a   thread   other   than   the   thread