private void cl_onThreadEnd(LogServer_Client sender)
 {
     discon_clients.Add(sender);
     if (this.onClientDisconnect != null)
     {
         this.onClientDisconnect(sender.Address);
     }
 }
        private void _exec()
        {
            this.running = true;
            try
            {
                this.tcp_server.Start();

                while (this.running == true)
                {
                    while (this.tcp_server.Pending())
                    {
                        TcpClient client = this.tcp_server.AcceptTcpClient();

                        LogServer_Client cl = new LogServer_Client(client);
                        cl.onThreadEnd += new LogServer_Client.ThreadEnd(cl_onThreadEnd);
                        this.clients.Add(cl);
                        cl.Send(greeting);
                        if (logMutex.WaitOne() == true)
                        {
                            try
                            {
                                foreach (string line in this.logLines)
                                {
                                    cl.Send(line);
                                }
                            }
                            finally
                            {
                                logMutex.ReleaseMutex();
                            }
                        }
                        cl.Start();
                        if (this.onClientConnect != null)
                        {
                            this.onClientConnect(cl.Address);
                        }
                    }

                    if ((unsentLines.Count > 0) && (logMutex.WaitOne() == true))
                    {
                        try
                        {
                            foreach (string line in unsentLines)
                            {
                                sendLine(line);
                            }

                            unsentLines.Clear();
                        }
                        finally
                        {
                            logMutex.ReleaseMutex();
                        }
                    }

                    foreach (LogServer_Client cl in discon_clients)
                    {
                        clients.Remove(cl);
                    }
                    discon_clients.Clear();

                    Thread.Sleep(10);
                }

                foreach (LogServer_Client cl in this.clients)
                {
                    cl.Stop();
                    cl.Join();
                }

                this.tcp_server.Stop();
            }
            catch (Exception ex)
            {
                if (this.onServerException != null)
                {
                    this.onServerException(ex);
                }
            }

            this.running = false;
        }