客户端未能启动建议循环

发布于 2024-09-13 00:12:25 字数 1181 浏览 8 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文