I am having an issue trying to update the GUI text boxes. I am using the following code that gets called after the window is displayed but if I put a break point on the first line of the code within the Dispatcher, it never gets called. If I put a breakpoint on the first line with UpdateDisplay, that indeed gets called.
private void UpdateDisplay()
{
Application.Current.Dispatcher.Invoke(TimeSpan.FromMilliseconds(1), _ =>
{
apnTextBox.Text = SystemConfigurationClass.configData.apn;
apnTextBox.Invalidate();
mqttUseLoginCheckBox.IsChecked = SystemConfigurationClass.configData.useLogin;
mqttUseLoginCheckBox.Invalidate();
mqttServerTextBox.Text = SystemConfigurationClass.configData.mqttServer;
mqttServerTextBox.Invalidate();
mqttPortTextBox.Text = SystemConfigurationClass.configData.mqttPort.ToString();
mqttPortTextBox.Invalidate();
mqttUsernameTextBox.Text = SystemConfigurationClass.configData.mqttUsername;
mqttUsernameTextBox.Invalidate();
mqttPasswordTextBox.Text = SystemConfigurationClass.configData.mqttPassword;
mqttPasswordTextBox.Invalidate();
return null;
}, null);
}
Is this the correct way to update the GUI? I know it has to be done from a dispatcher as they are not visible outside the main GUI thread.
I also found that if I call UpdateDisplay from Program.cs in the same function that selects the current window for viewing, I can do this without the Dispatcher.Invoke above.