views:

58

answers:

1

Up to now when I wanted to update an UI control from a non UI thread I used syntax like:

Dispatcher.Invoke(DispatcherPriority.Normal,
                  new Action(()=>Label1.Content="New Content"));

Now I am reading some more about it I keep finding the following syntax:

Label1.Dispatcher.Invoke(//same arguments;

Is the latter better? Why would I chose one method over the other?

+4  A: 

I would personally use the one for the control itself, as then you don't need to worry about even knowing the containing window.

However, I wouldn't expect it to matter - at least in normal Win32, all the controls within a single window ought to be "owned" by a single UI thread. I would expect that to carry over to WPF too. (There are some cases where this doesn't apply, when one window is reparented in another, but that's pretty rare.)

Jon Skeet