客户端未能启动建议循环
我正在使用 NDde 进行 DDE 事务。我正在尝试使用线程创建 DdeClient 的多个实例。对于本例,我们假设有 3 个线程。如果我用单线程尝试它,它会起作用。但任何超过 2 的值都会给我返回一个错误,即它无法启动建议循环。问题是为什么当它是多线程并且每个线程都有自己的“建议”处理程序时它不起作用?任何帮助都会非常有用
我做了什么: 1)在一个循环中,我调用了 Thread t = new Thread(CreateDdeThread);它链接到 private void CreateDdeThread(object data) 2)在 private void CreateDdeThread(object data) 中,我创建了一个 DdeClient 及其必要的事件处理程序。
private void CreateDdeThread(object data)
{
Console.WriteLine("CreateDdeThread");
Spark spark = (Spark)data;
DdeClient ddeClient = new DdeClient("Client", spark.GetClient() + ".Name");
ddeClient.Disconnected +=new
EventHandler<DdeDisconnectedEventArgs>(OnDisconnected);
ddeClient.Connect();
ddeClient.Advise += new EventHandler<DdeAdviseEventArgs>(OnAdvise);
ddeClient.StartAdvise(
"Address." + spark.GetStreet(), 1, true, true, 60000, ddeClient);
}
private void OnAdvise(object sender, DdeAdviseEventArgs args)
{
string[] p = args.Text.Split(new string[] { "\n" }, StringSplitOptions.None);
foreach (string s in p)
{
Console.WriteLine(s);
}
}
I am using NDde for DDE transactions. I am trying to create multiple instances of DdeClient using threads. For this example, we will assume there is 3 threads. If I try it with a single thread, it works. But anything more than 2 returns me an error whereby it failed to initiate an advise loop. The question is why would it not work when it is multi threaded and each thread have their own "advise" handler? Any help will be greatful
What I did:
1) In a loop, I called Thread t = new Thread(CreateDdeThread); which is linked to private void CreateDdeThread(object data)
2) In private void CreateDdeThread(object data), I create a DdeClient with their necessary eventhandlers.
private void CreateDdeThread(object data)
{
Console.WriteLine("CreateDdeThread");
Spark spark = (Spark)data;
DdeClient ddeClient = new DdeClient("Client", spark.GetClient() + ".Name");
ddeClient.Disconnected +=new
EventHandler<DdeDisconnectedEventArgs>(OnDisconnected);
ddeClient.Connect();
ddeClient.Advise += new EventHandler<DdeAdviseEventArgs>(OnAdvise);
ddeClient.StartAdvise(
"Address." + spark.GetStreet(), 1, true, true, 60000, ddeClient);
}
private void OnAdvise(object sender, DdeAdviseEventArgs args)
{
string[] p = args.Text.Split(new string[] { "\n" }, StringSplitOptions.None);
foreach (string s in p)
{
Console.WriteLine(s);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论