各个模块/视图在 Prism 中的行为方式(WPF 的复合应用程序模式)
这可能是一个完全n00b的问题,因为我对 PRISM 知之甚少,但让我们假设我有一个由 3 个控件组成的复合应用程序的假设情况:控件 A(图表)、控件 B(表格)和控制C(计算器)。
所有这些控件都运行在同一个 UI 线程上吗?例如,如果控制 A 开始在其主线程上进行一些疯狂的计算并且阻塞 - 整个容器会冻结吗?
如果这个问题的答案是肯定的 - 是告诉 A 的“控制团队”不要这样做的唯一解决方案吗?或者我们可以考虑一些设计模式来处理它?
如果这个问题的答案是否定的 - 您能否解释一下这是如何工作的,或者向我指出一些我可以查看的有关该主题的文档?
谢谢
This may come off as a totally n00b question as I know very little about PRISM at all yet, but let's imagine I have a hypothetical situation of a composite application consisting of 3 controls: Control A (a chart), Control B (a table) and Control C (a calculator).
Are all of these controls running on the same UI thread? For example if Control A starting doing some crazy calculation on it's main thread and was blocking - would the entire container freeze?
If the answer to this question is yes - is the only solution to tell the "control team" for A not to do that? Or is there some design pattern we could think about to handle it?
If the answer to this question is no - can you explain a bit how this works or point me at some documentation I could review on the subject?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WPF 使用 Dispatcher 线程来同步 UI 访问,因此本质上它们都将在同一线程上运行。您仍然可以以通常的方式实现异步调用,但是要更新 UI,您需要使用 Dispatcher 重新加入 Dispatcher 线程:
您也可以在使用 EventAggregator 订阅事件时执行此操作,如下所示:
这里有一些关于主题:
http://msdn.microsoft.com/en-us/library /ms741870.aspx#threading_overview
WPF uses a Dispatcher thread to synchronize UI access, so yes essentually they would all be running on the same thread. You can still implement asynchronous calls in the usual way, but to update the UI you need to rejoin the Dispatcher thread using the Dispatcher:
You can also do this when using the EventAggregator to subscribe to events as follows:
There's some more info here on the subject:
http://msdn.microsoft.com/en-us/library/ms741870.aspx#threading_overview