I have this method what called from an Async method
private void SocketConnected(Object sender, EventArgs e) {
//Some code
connectedLabel.Content = "Connected";
}
And the connectedLabel.Content = "Connected";
throws an error. How can I update this from this method? I've seen a few post saying use Invoke, however, that gives me an error that label doesn't have a Invoke method.
EDIT:
From looking at Dispatcher as mentioned in the comments I've got this which works.
private string message;
public void UpdateConnected()
{
connectedLabel.Content = message;
}
private void SocketConnected(Object sender, EventArgs e) {
//Some stuff
message = "Connected";
this.Dispatcher.BeginInvoke(new Action(this.UpdateConnected), DispatcherPriority.Background);
}
Is that the correct usage of the Dispatcher?