收到多次发布后如何防止申请关闭? [英] How to prevent application from closing after multiple publish received?

查看:106
本文介绍了收到多次发布后如何防止申请关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了控制台应用程序,它为MQTT Broker订阅了多个主题。我已经注册了MqttMsgPublishedReceived,即使在订阅主题上有新数据时也会触发。该应用程序正在为单个订阅正常运行。但是当我尝试运行多个订阅时,应用程序正在关闭。如何使MqttMsgPublisheReceived事件处理多个发布。下面是我的代码片段。

i跟随以下代码

I have created the console application which subscribes to multiple topics to the MQTT Broker. I have registered MqttMsgPublishedReceived even which triggers whenever there is a new data on the subscribed topic. The application is running properly for a single subscription. But when I tried to run the multiple subscriptions, the application is closing. How to make the MqttMsgPublisheReceived event to handle the multiple publishes. Below is my code snippet.
i followed following code

for(int i=0;i<client.Length;i++)




{




subscribe(hostname,port,clientid);<pre>

}

}

public void subscribe()




{




 client.MqttMsgPublishReceived+=client_MqttMsgPublishReceived
<pre>}




public void client_MqttPublishReceived(object sender,MqttMsgPublishEventargs e)




{




//business logic




}



MqttMsgPublishReceived事件因同步消息而崩溃。提前致谢



我尝试过:



我试过打电话单独的每个主题。适当的应用程序。每当我运行多个应用程序时它就会崩溃。


MqttMsgPublishReceived event crashing for simulataneous messages. Thanks in advance

What I have tried:

I tried calling individually each topic.For which applcation properly. It is crashing whenever i run multiple applications.

推荐答案

根据发布的代码无法回答这个问题,因为这是不完整的。



您至少应检查异常并报告它们以了解应用程序何时何地终止并获取有意义的错误消息。如果这没有帮助你必须在调试器中运行它。



另请阅读使用过的函数的文档,并观察一些变量可能不会由多个共享订阅(对这些变量使用数组)。
This can't be answered based on the posted code because that is incomplete.

You should at least check for exceptions and report them to know where and when the application terminates and to get meaningful error messages. If that does not help you have to run it within a debugger.

Read also the documentation of the used functions and observe that some variables should be probably not shared by multiple subscriptions (use an array for those variables).


这篇关于收到多次发布后如何防止申请关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆