private void ServerControl_Unchecked(object sender, RoutedEventArgs e)
 {
     if (!this.tcpServerEngine.Disposed)
     {
         tcpServerEngine.ChangeListenerState(false);
         GC.GetTotalMemory(true);
         MessageBox.Show("停止监听");
         this.textBox_port.IsReadOnly = true;
     }
 }
Example #2
0
        public void StartServer()
        {
            try
            {
                if (SockterServerEngine == null)
                {
                    var port  = ConfigTools.Get("port");
                    var _port = port == null || port.Length <= 0 ? 9909 : int.Parse(port);
                    SockterServerEngine = NetworkEngineFactory.CreateTextTcpServerEngine(_port, new DefaultTextContractHelper("\0"));//DefaultTextContractHelper是StriveEngine内置的ITextContractHelper实现。使用UTF-8对EndToken进行编码。
                }
                //判断 相关的监听事件是否注册
                if (IsSocketServerInitialized)
                {
                    SockterServerEngine.ChangeListenerState(true);
                }
                else
                {
                    InitializeTcpServerEngine();
                }

                //this.ShowListenStatus();
            }
            catch (Exception ee)
            {
                Console.WriteLine(ee.Message);
                if (ee.Message.IndexOf("there's one StriveEngine server instance running") >= 0)
                {
                    var res = MessageBox.Show("已打开一个实例或者前面实例的进程为未完全退出,是否重启?\r\n是:重启\r\n否:关闭\r\n取消:不做任何处理", "警告", MessageBoxButtons.YesNoCancel);
                    if (DialogResult.Yes == res)
                    {
                        Application.ExitThread();
                        Application.Exit();
                        Application.Restart();
                        Process.GetCurrentProcess().Kill();
                    }
                    else if (DialogResult.No == res)
                    {
                        Application.ExitThread();
                        Application.Exit();
                        Process.GetCurrentProcess().Kill();
                    }
                }
            }
            services = this;
        }