1

我需要在 Windows 窗体和控制台应用程序中注册 DDE 服务器。我已经在 Windows 窗体应用程序的各个点尝试了注册码,但它似乎没有注册。我已经在 frmMain 和 Program.cs Main() 中尝试过了。

当我尝试使用 DDE 服务器时,我收到标准无法连接消息:“MainForm_Load:客户端无法连接到”CRMIntegrator|myservice”。确保服务器应用程序正在运行并且它支持指定的服务名称和主题名称一对。”

这是我的注册码:

public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
            try
            {
                // Create a server that will register the service name 'myapp'.
                using (DdeServer server = new MyServer("CRMIntegrator"))
                {
                    // Register the service name.
                    server.Register();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
4

1 回答 1

2

您在这里没有正确使用using关键字。在 Register() 调用之后,服务器将立即被释放。这确实使得它不太可能在 Load 事件运行时仍然存在。

使服务器变量成为表单类中的字段。在表单关闭之前不要释放它,在 OnFormClosed() 方法覆盖或 FormClosed 事件处理程序中这样做。

于 2011-02-07T15:01:00.480 回答