我需要在 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);
}
}
}
最佳答案
您在这里没有适本地使用 using 关键字。 Register() 调用后,服务器将立即处理掉。这确实使得它不太可能在 Load 事件运行时仍然存在。
使 server 变量成为表单类中的一个字段。在表单关闭之前不要处理它,在 OnFormClosed() 方法覆盖或 FormClosed 事件处理程序中执行此操作。
关于windows - 在 Windows 窗体应用程序与控制台应用程序中注册 DDE 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4922472/