Hi I am trying to update a label in my WPF GUI from another class, which is not the GUI with this code:
System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(new Action(() =>
{
((MainWindow)System.Windows.Application.Current.MainWindow)
.lblError.Content = exception.Message;
}));
Sometimes however I get the following exception and the update does not work:
Exception thrown: 'System.InvalidOperationException' in WindowsBase.dll (" The calling thread can not access this object because the object is owned by another thread .")
Why does my delegate not work? Is there an easy way to do what I want to do (update a label of my GUI from another class) without too much effort?