static void Main(string[] args) { thread = new Thread(new ThreadStart(() => ThreadRun())); thread.IsBackground = true; thread.Start(); TcpListenerSocket tcpListenerSocket = new TcpListenerSocket(12000); tcpListenerSocket.Start(); Console.WriteLine($"tcpListenerSocket.Start()."); Console.WriteLine($"Press any key to stop server."); Console.ReadLine(); tcpListenerSocket.Stop(); //Console.ReadLine(); }
protected override void OnStop() { // TODO: 在此处添加代码以执行停止服务所需的关闭操作。 tcpListenerSocket.Stop(); }