public static void UIThreadSetValue(this DependencyObject me, DependencyProperty dp, object value)
{
if (me != null)
{
if (Application.Current.Dispatcher != System.Windows.Threading.Dispatcher.CurrentDispatcher)
{
if (!Application.Current.Dispatcher.HasShutdownFinished
&& !Application.Current.Dispatcher.HasShutdownStarted)
{
Application.Current.Dispatcher.Invoke(
new Action<DependencyProperty, object>(me.SetValue), dp, value);
}
}
else
{
me.SetValue(dp, value);
}
}
}
}