0

フォームを閉じた後にフォーム内の 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...";
            }
4

0 に答える 0