关闭表单后如何关闭表单中的 TCP 通道,我想再次打开表单以使用相同的表单启动 TCP 通道。但它返回一条错误消息,告知 TCP 通道已注册。我尝试了几种方法来仅关闭此表单,但由于 Application.Exit 正在关闭整个应用程序而返回失败
private void EstablishRemote()
{
SoapServerFormatterSinkProvider soap = new SoapServerFormatterSinkProvider();
BinaryServerFormatterSinkProvider binary = new BinaryServerFormatterSinkProvider();
soap.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
binary.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
soap.Next = binary;
Hashtable table = new Hashtable();
table.Add("port", ServerPortValue.Text);
TcpChannel channel = new TcpChannel(table, null, soap);
FTPServer.Logger = Logger;
ChannelServices.RegisterChannel(channel,false);
RemotingConfiguration.ApplicationName = "FTPServerAPP";
RemotingConfiguration.RegisterWellKnownServiceType(typeof(FTPServer),"ftpserver.svr", WellKnownObjectMode.Singleton);
Logger.Text += Environment.NewLine+ "***** TCP Channel has been published... *****";
}
private void StartServer_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(ServerPortValue.Text))
{
MessageBox.Show("Please enter server port.", "Server", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
EstablishRemote();
ServerPortValue.ReadOnly = true;
StartServer.Enabled = false;
ServerStatusMessage.Text = "Server has been started...";
}