开发者

Which Dispatcher to use? The Window's or the Control's?

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?


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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜