views:

21

answers:

1

Can someone be so kind as to give me a concise (general is fine) set of rules for what data/methods can and cannot be accessed from a secondary (non-UI) thread?

A: 

I would say that it is any DependencyObject that was created by the UIThread.

I would suggest using this extension method, when you are not sure...

public static class Extensions
{
    public static void FastInvoke(this Dispatcher dispatcher, Action action)
    {
        if (dispatcher.CheckAccess())
            action.Invoke();
        else
            dispatcher.BeginInvoke(action);
    }
}

Use it like this:

Dispatcher.FastInvoke(delegate
                {
                    StatusMessageText.Text = "OK";
                });
umbyersw
thanks- that's a good start. I can also tell that if a UI element is bound to a property of an INotifyPropertyChanged derived object, then modifying this property's value in a background thread will also fail. So it would seem any UI element or property which is bound to a UI element will cause an error if accessed by a non-UI thread. Are there any other rules?
skj