Try one of these two solutions
public static void InvokeIfRequired(this DispatcherControl control, Action operation)
{
if (control.Dispatcher.CheckAccess())
{
operation();
}
else
{
control.Dispatcher.BeginInvoke(DispatcherPriority.Normal, operation);
}
}
Then, it's simple to do:
Dispatcher.CurrentDispatcher.InvokeIfRequired(()=>{ theButton.Content="Hello"; });
or this
public void Test()
{
Button theButton = button1 as Button;
if (theButton != null)
{
if (theButton.Dispatcher.CheckAccess())
{
theButton.Content = "Hello";
}
else
{
theButton.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
(Action)(() => { theButton.Content = "Hello"; }));
}
}
}
both found here on CodeProject!!