获取对渲染线程的引用,以允许线程安全的数据访问
最近,我遇到了涉及使用多线程和共享对绑定到 WPF 控件的属性的访问的问题。这些崩溃往往会在时间上随机发生,但可以持续复制。
因此,为了允许对绑定到 WPF 控件的类进行线程安全数据访问,我想要尝试做的是获取对渲染线程调度程序的引用,并确保在我的视图模型中该调度程序用于访问它们的属性。
这个概念合理吗?它是否允许从其他线程访问绑定到我的控件的数据? (访问我的意思是获取/设置)。
如何获取渲染线程的引用?我可以简单地获取对创建 App 类实例的线程的引用吗?
谢谢, 亚历克斯.
Recently I have been running into issues involving the use of multiple threads and sharing access to properties which are bound to WPF controls. These crashes tend to occur at random places in time, but can be replicated with persistance.
So what I wanted to try and do to allow thread safe data access to classes which are bound to WPF controls is gain a reference to the rendering thread dispatcher and make sure in my view models that this dispatcher is used to access their properties.
Is this concept sound? Will it allow the data which is bound to my controls to be accessed from other threads? (by accessed I do mean get/set).
How can I get a reference to the rendering thread? Can I simply get a reference to the thread which creates an instance of the App class?
Thanks,
Alex.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,我认为
Application.Current.Dispatcher
会始终为您提供 UI 调度程序,因此真的不需要用于访问数据投标调度程序(应该是 UI 调度程序本身)的特殊代码。As long as I know, I think
Application.Current.Dispatcher
will always give you the UI dispatcher so there is really no need to have a special code to gain access to the data bidning dispatcher (which should be the UI dispatcher itself).