Continuously receiving messages (waiting for messages in the background) #1799
-
Hi :) sorry for this really simple question but I am quiet new to async and multi-threading. I tried it in an really old version (3.08) with the synchronous approach and that worked but with the "ApplicationMessageReceivedAsync" I am not getting any messages. To run the task, I tried using "Task newTask = HandleMessage();" after the "InitializeComponent();" and also "Task.Run(() => HandleMessage());" inside a button-click event. If I debug my code, I see that (when clicking the button), the "HandleMessage()" is called and executed but nothing happens afterwards and I don't think, that there is a task being created with the Handle to react to any incoming messages. I hope this makes sense and someone can help me :) Kind regards and thanks in advance, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 15 replies
-
@JustTotallyMe I recently started looking at MQTTnet again. In the past, I created the following issue: It sort of works as shown in the following sample PR I just created: |
Beta Was this translation helpful? Give feedback.
-
How are you "trying" this? Where are you initializing the client?
What do you mean by "how to start the Task for this?" This shows how to subscribe to the event: MQTTnet/Samples/Client/Client_Subscribe_Samples.cs Lines 33 to 39 in 8ad8692 Where did you wire this in your code? |
Beta Was this translation helpful? Give feedback.
@JustTotallyMe No, it does not. Your code immediately disposes of the client (using).
Your click handler should at most do:
The other setup stuff like creating a client and registering a event handler/callback should be done in the lifetime of the application or window/form/etc lifetime