private void DoBeginAcceptTcpClient()
        {
            MessageListenerWorker mlw = null;

            try
            {
                while (true)
                {
                    lock (Sync)
                    {
                        TcpClientConnectedEvent.Reset();
                        Sync.IsAcceptingConn = (Sync.NumOfConn < MaxConnections || MaxConnections <= 0);
                    }

                    if (Sync.IsAcceptingConn)
                    {
                        TcpClient client = _server.AcceptTcpClient();
                        if (client.Client.RemoteEndPoint is IPEndPoint)
                        {
                            IPEndPoint remoteAddr = (IPEndPoint)client.Client.RemoteEndPoint;
                            IPEndPoint localAddr  = (IPEndPoint)client.Client.LocalEndPoint;
                            Logger.GetInstance().WriteLine("Accepting request from " + remoteAddr.Address + ":" + remoteAddr.Port
                                                           + " to " + localAddr.Address + ":" + localAddr.Port,
                                                           LogLevel.Notice);
                        }
                        lock (Sync)
                        {
                            Sync.NumOfConn++;
                        }
                        new Thread(this.DoAcceptTcpClientCallback).Start(client);
                    }
                    else
                    {
                        TcpClientConnectedEvent.WaitOne();
                    }

                    if (_stopped)
                    {
                        return;
                    }
                }
            }
            catch (Exception e)
            {
                Logger.GetInstance().Write(e);
                if (mlw != null)
                {
                    mlw.Close();
                }
            }
            finally
            {
                Stop();
            }
        }
        private void DoAcceptTcpClientCallback(Object clientObject)
        {
            if (_stopped)
            {
                return;
            }
            MessageListenerWorker mlw = null;

            try
            {
                TcpClient client = (TcpClient)clientObject;
                mlw = new MessageListenerWorker(client, this);
                mlw.AcceptMessage();
            }
            catch (Exception e)
            {
                Logger.GetInstance().Write(e);
                if (mlw != null)
                {
                    mlw.Close();
                }
            }
        }