When I use this piece of code, MessageOutput.Text is set 2 times, which means the code is executed twice, since I do not set MessageOutput.Text elsewhere. Whenever I receive a new message, this method is called and it should update the user interface. 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");
});
}
source
share