When I use this snippet of code The MessageOutput.Text is set 2 times, which means that the code is executed twice since I don't set the MessageOutput.Text anywhere else. Whenever I get a new message, this method is called and it is supposed to update the UI. Why is this happening and how can I fix it?
async void MessageReceived(DatagramSocket socket, DatagramSocketMessageReceivedEventArgs eventArguments)
{
uint stringLength = eventArguments.GetDataReader().UnconsumedBufferLength;
string receivedMessage = eventArguments.GetDataReader().ReadString(stringLength);
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
MessageOutput.Text += (receivedMessage + "\n");
});
}