Skip to content

Continuously receiving messages (waiting for messages in the background) #1799

Closed Answered by ramonsmits
JustTotallyMe asked this question in Q&A
Discussion options

You must be logged in to vote

@JustTotallyMe No, it does not. Your code immediately disposes of the client (using).

Your click handler should at most do:

async void button1_Click(object sender, EventArgs e)
{
    var applicationMessage = new MqttApplicationMessageBuilder()
                .WithTopic("samples/temperature/living_room")
                .WithPayload("19.5")
                .Build();

    await mqttSenderClient.PublishAsync(applicationMessage, CancellationToken.None);
}

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

Replies: 2 comments 15 replies

Comment options

You must be logged in to vote
3 replies
@JustTotallyMe
Comment options

@ramonsmits
Comment options

@JustTotallyMe
Comment options

Comment options

You must be logged in to vote
12 replies
@JustTotallyMe
Comment options

@ramonsmits
Comment options

@JustTotallyMe
Comment options

@ramonsmits
Comment options

Answer selected by JustTotallyMe
@ramonsmits
Comment options

@JustTotallyMe
Comment options

@JustTotallyMe
Comment options

@CZEMacLeod
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants