C# 多个主题和项目的NDde服务器和上下文。我需要多个实例吗?
我已经检查了这个问题:,还有这个,还有其他一些来源,在处理这个问题时;然而,似乎不是我不了解一些基本知识,就是我一直尝试的方式没有明确支持它 我正在努力编写一个类库,将一些值(大约六个)发送到一个更喜欢使用DDE输入的应用程序,一次发送几个 让我困惑的是,我是否需要这样做,才能通过热链接发送我的邮件C# 多个主题和项目的NDde服务器和上下文。我需要多个实例吗?,c#,dde,ndde,C#,Dde,Ndde,我已经检查了这个问题:,还有这个,还有其他一些来源,在处理这个问题时;然而,似乎不是我不了解一些基本知识,就是我一直尝试的方式没有明确支持它 我正在努力编写一个类库,将一些值(大约六个)发送到一个更喜欢使用DDE输入的应用程序,一次发送几个 让我困惑的是,我是否需要这样做,才能通过热链接发送我的邮件 public AutoServer(string service, string ItemDataLabel) : base(service)
public AutoServer(string service, string ItemDataLabel)
: base(service)
{
// Create a timer that will be used to advise clients of new data.
_Timer.Elapsed += this.OnTimerElapsed;
_Timer.Interval = 30;
_Timer.SynchronizingObject = this.Context;
DataLabel = ItemDataLabel;
//OnAdvise(Symbol, DataLabel, 1);
}
private void OnTimerElapsed(object sender, ElapsedEventArgs args)
{
// Advise all topic name and item name pairs.
OnAdvise(Current, DataLabel, 1);
Advise(Current, DataLabel);
}
public string Data;
public string DataLabel;
}
以这种方式放几个带有不同字符串标签的OnAdvise,在OnAdvise内部写下在每个标签组合的情况下OnAdvise应该做什么
另一个选项似乎注册了几个服务器实例,并在OnAdvice中写出每种参数组合的所有细节。
但最困难的事情来了。我尝试了这两种方法,但得到的异常是:在创建窗口句柄之前,不能对控件调用Invoke或BeginInvoke。换句话说,我需要为每个服务器分别为每个项目创建一个上下文(多个onadvice放在一起似乎不起作用)
那么,将表单和上下文初始化放在一个具有各自服务器注册的方法中,以及像项目一样多的方法中,并同时运行它们是否正确
例如:
namespace lookout_DDE
{
public partial class lookout_DDE_class : AutoGroup
{
public partial class ServerContextForm : Form
{
private DdeContext context = null;
private void ContextRunner()
{
context = new DdeContext(this);
context.Initialize();
}
}
}
}
及
及
我刚刚发现我必须为运行上下文保留表单,因此需要使用单独的方法来代替
因此,重申这个问题的最佳方式可能是,我是否需要使用多个表单和上下文,并注册服务器实例,以便运行多个项目,或者我应该在服务器类中实现OnAdvice
看,我对C#和编程一般来说都是新手,然而,我正试图“在过程中”学习编程。如果您能提供帮助,请提供建议。:) 到目前为止找到了部分解决方案: 1) 需要有多个服务器实例,因为OnAdvice可以由客户端应用程序订阅一次。(如果不是你写的,谁知道它是怎么做到的) 2) 每个服务器都可能需要一个单独的(更好的)上下文,并且分别需要一个表单,但是可能需要一个单独的上下文。没有测试最后一个 现在,我想起了一个关于“潜在”这个词的坏/好笑话。猜猜看。
没有任何意见是多么遗憾啊 到目前为止找到了部分解决方案: 1) 需要有多个服务器实例,因为OnAdvice可以由客户端应用程序订阅一次。(如果不是你写的,谁知道它是怎么做到的) 2) 每个服务器都可能需要一个单独的(更好的)上下文,并且分别需要一个表单,但是可能需要一个单独的上下文。没有测试最后一个 现在,我想起了一个关于“潜在”这个词的坏/好笑话。猜猜看。 没有任何意见是多么遗憾啊
namespace lookout_DDE
{
public partial class lookout_DDE_class : AutoGroup
{
public partial class ServerContextForm : Form
{
public ServerContextForm()
{
InitializeComponent();
ContextRunner();
}
}
}
}
[STAThread]
partial void RunServer()
{
using (ServerContextForm ContextForm = new ServerContextForm())
{
Application.Run(ContextForm);
ServerStarter("A1");
}
using (ServerContextForm ContextForm = new ServerContextForm())
{
Application.Run(ContextForm);
ServerStarter("A2");
}
using (ServerContextForm ContextForm = new ServerContextForm())
{
Application.Run(ContextForm);
ServerStarter("A3");
}
using (ServerContextForm ContextForm = new ServerContextForm())
{
Application.Run(ContextForm);
ServerStarter("A4");
}
using (ServerContextForm ContextForm = new ServerContextForm())
{
Application.Run(ContextForm);
ServerStarter("A5");
}
}