private void MainWindow_Load(object sender, EventArgs e) { /*if (Server == null) * { * try * { * Server = new TcpListenerPlus(IPAddress.Parse(ip), port); * Server.OnThreadTaskRequest += new TcpListenerPlus.ThreadTaskRequest(GetAnswer); * } * * catch (Exception) * { * if (Server != null) * { * Server.Stop(); * Server = null; * } * MessageBox.Show(this, "启动服务器失败!", "信息"); * } * } * else * { * Server.Stop(); * Server = null; * } */ if (udp_Server == null) { try { udp_Server = new UdpListenerPlus(port); udp_Server.OnThreadTaskRequest += new UdpListenerPlus.ThreadTaskRequest(Handle_Udp_Msg); } catch (Exception) { if (udp_Server != null) { udp_Server.Stop(); udp_Server = null; } MessageBox.Show(this, "启动服务器失败!", "信息"); } } else { udp_Server.Stop(); udp_Server = null; } m_thread_clearMemory = new Thread(new ThreadStart(clear_Memory)); m_thread_clearMemory.IsBackground = true; m_thread_clearMemory.Start(); this.WindowState = FormWindowState.Minimized; }
private void MainWindow_Load(object sender, EventArgs e) { /*if (Server == null) { try { Server = new TcpListenerPlus(IPAddress.Parse(ip), port); Server.OnThreadTaskRequest += new TcpListenerPlus.ThreadTaskRequest(GetAnswer); } catch (Exception) { if (Server != null) { Server.Stop(); Server = null; } MessageBox.Show(this, "启动服务器失败!", "信息"); } } else { Server.Stop(); Server = null; } */ if (udp_Server == null) { try { udp_Server = new UdpListenerPlus(port); udp_Server.OnThreadTaskRequest += new UdpListenerPlus.ThreadTaskRequest(Handle_Udp_Msg); } catch (Exception) { if (udp_Server != null) { udp_Server.Stop(); udp_Server = null; } MessageBox.Show(this, "启动服务器失败!", "信息"); } } else { udp_Server.Stop(); udp_Server = null; } m_thread_clearMemory = new Thread(new ThreadStart(clear_Memory)); m_thread_clearMemory.IsBackground = true; m_thread_clearMemory.Start(); this.WindowState = FormWindowState.Minimized; }