Dispatcher的高级内容 [英] Advanced content on Dispatcher

查看:56
本文介绍了Dispatcher的高级内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我正在寻找关于WPF中Dispatcher的完整演讲,就像它是什么一样,单个应用程序中可以存在多少个disptacher细节。我正在谷歌上搜索它,但只有基础知识。无法在Dispatcher上找到任何有太多细节的书籍或帖子。

解决方案

System.Windows.Threading.Dispatcher的实例。属性 Dispatcher.CurrentDispatcher 返回与调用线程关联的实例,根据延迟初始化模式创建之前尚未创建的实例。请参阅:

https://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.currentdispatcher%28v=vs.110%29.aspx [ ^ ],

https://en.wikipedia.org/wiki/Lazy_initialization [< a href =https://en.wikipedia.org/wiki/Lazy_initializationtarget =_ blanktitle =New Window> ^ ]。



如果在不同的线程中执行此操作,则很容易检查所获得的引用是否引用了不同的对象。您可以从几个不同的线程(包括UI线程)调用此属性,并使用 System.Object.ReferenceEquals 检查引用。您将看到 Dispatcher 对象在引用上是不同的。



-SA

Hello ,

I am looking for a complete talk on Dispatcher in WPF, like what it is, how many disptacher can exist in a single application and all other details. I am googling it but only basics are there. Not able to find any book or post with too much details on Dispatcher.

解决方案

The instances of System.Windows.Threading.Dispatcher are created per thread. The property Dispatcher.CurrentDispatcher returns an instance associated with the calling thread, creating one of it was not yet created before, according the lazy initialization pattern. Please see:
https://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.currentdispatcher%28v=vs.110%29.aspx[^],
https://en.wikipedia.org/wiki/Lazy_initialization[^].

It's easy to check up that the references obtained reference different objects if you do it in different threads. You can call this property from several different threads, including the UI thread, and check up the references using System.Object.ReferenceEquals. You will see that the Dispatcher objects are referentially different.

—SA


这篇关于Dispatcher的高级内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆