Which dispatcher to use? Window or Control?

Until now, when I wanted to update a UI control from a non-UI thread, I have used syntax like:

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

      

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

Label1.Dispatcher.Invoke(//same arguments;

      

Is the latter better? Why did I choose one method over the other?

+2


source to share


1 answer


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



However, I would not expect this to make a difference - at least in normal Win32, all controls in one window must be "owners" of the same UI thread. I would expect porting to WPF too. (There are some cases where this does not apply where one window is overwritten in another, but this is quite rare.)

+6


source







All Articles