public static void OnStartupService(ServiceHostProxy host) { // 启动登录连接服务线程 ThreadPool.QueueUserWorkItem(new WaitCallback(obj => { while (IsAppRunning) { var binding = new NetTcpBinding(SecurityMode.None); binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows; binding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign; binding.OpenTimeout = TimeSpan.MaxValue; binding.SendTimeout = TimeSpan.MaxValue; binding.ReceiveTimeout = TimeSpan.MaxValue; binding.MaxReceivedMessageSize = 1024 * 1024; binding.MaxBufferPoolSize = 1024 * 1024; if (!host.StartService(typeof(MainService), typeof(IChessService), binding, 8601, "MainService")) { Thread.Sleep(1000); continue; } ServiceProxy = host; break; } })); }
private void MainForm_Load(object sender, EventArgs e) { var host1 = new ServiceHostProxy("主服务"); host1.OnErrorMessage += PushMessage; host1.OnMessage += PushMessage; Program.OnStartupService(host1); }