获取对渲染线程的引用,以允许线程安全的数据访问

发布于 2024-12-09 08:52:11 字数 280 浏览 0 评论 0原文

最近,我遇到了涉及使用多线程和共享对绑定到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

此生挚爱伱 2024-12-16 08:52:11

据我所知,我认为 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文