private void RemoveClientOnline(ClientConnecting client)
        {
theRemove:
            try
            {
                if (this.listClients.Remove(client))
                {
                    Logger.Write("Co client tat!");
                }
                if (!this.listClients.Remove(client))
                {
                    Logger.Write("Da remove client " + client.User.UserName);
                }
            }
            catch
            {
                goto theRemove;
            }
            new Thread(() => {
                foreach (ClientConnecting item in listClients)
                {
                    item.SendUser(client.User);
                }
            }).Start();
            //SendAllUser(client, false);
            if (threadAccept.ThreadState == ThreadState.Suspended)
            {
                threadAccept.Resume();
            }
        }
 private void Run()
 {
     serverSocket.Listen(10);
     while (true)
     {
         Socket client = serverSocket.Accept();
         //Console.WriteLine("Co client ket noi!");
         ClientConnecting tempClient = new ClientConnecting(client);
         tempClient.Online = AddOnline;
     }
 }
 private void RemoveClientOnline(ClientConnecting client)
 {
     //TheServer.Instance.ChangeStatus(client.User.UserName);
     if (this.listClients.Remove(client))
     {
         Console.WriteLine("Co client tat!");
     }
     //SendAllUser(client, false);
     if (threadAccept.ThreadState == ThreadState.Suspended)
     {
         threadAccept.Resume();
     }
 }
        private void AddOnline(ClientConnecting user)
        {
            //this method still bug
            SendNotification(user);


            listClients.Add(user);
            user.Disconnected = RemoveClientOnline;
            user.Pass         = ProcessTranportObject;
            Logger.Write(user.User.UserName + " da dang nhap");
            if (listClients.Count > 19)
            {
                threadAccept.Suspend();
            }
        }
        private void SendNotification(ClientConnecting newClient)
        {
            new Thread(() => {
                if (listClients.Count > 0)
                {
                    foreach (ClientConnecting item in listClients)
                    {
                        if (item == newClient)
                        {
                            continue;
                        }
                        newClient.SendUser(item.User);

                        item.SendUser(newClient.User);
                    }
                }
                SendHistoryChatContent(newClient);
            }).Start();
        }
        private void SendNotification(ClientConnecting newClient)
        {
            new Thread(() => {
                if (listClients.Count > 0)
                {
                    foreach (ClientConnecting item in listClients)
                    {
                        //Send UserOnline to the new client
                        newClient.SendUser(item.User);

                        //Send new client to users online
                        item.SendUser(newClient.User);


                        Logger.Write(item.User.UserName);
                    }
                }
            }).Start();
        }
 internal void SendHistoryChatContent(ClientConnecting client)
 {
     client.SendListChatContent(client.User.GetHistoryChatContent());
 }