TVServerKodi.Listener.Stop C# (CSharp) Method

Stop() public method

public Stop ( ) : void
return void
        public void Stop()
        {
            try
            {
                Log.Debug("TVServerKodi: tcpListener.Stop()");
                Console.WriteLine("TVServerKodi: tcpListener.Stop()");
                stopme = true;

                if (m_listenThread != null)
                {
                    Log.Debug("TVServerKodi: Listenthread is aborting");
                    m_listenThread.Abort();
                    m_listenThread = null;
                }

                if (m_communicationThreads.Count > 0)
                {
                    Log.Debug("TVServerKodi: Stop all communication threads");
                    foreach (Thread thread in m_communicationThreads)
                    {
                        thread.Abort();
                    }
                    m_communicationThreads.Clear();
                    m_communicationThreads = null;
                }

                if (m_clients.Count > 0)
                {
                    Log.Debug("TVServerKodi: Closing all client connections");
                    foreach (TcpClient client in m_clients)
                    {
                        client.Close();
                    }

                    m_clients = null;
                }
            }
            catch (Exception)
            { }
        }

Usage Example

Esempio n. 1
0
        private void StopListenThread()
        {
            try
            {
                if (m_listener != null)
                {
                    if (connected)
                    {
                        TVServerConnection.CloseAll();
                    }

                    Log.Info("TVServerKodi: Stop listening");

                    m_listener.Stop();
                    m_listener = null;
                }
            }
            catch
            {
                Log.Error("TVServerKodi: StopListenThread failed!");
                Console.WriteLine("StopListenThread failed!");
            }
        }