各个模块/视图在 Prism 中的行为方式(WPF 的复合应用程序模式)

发布于 2024-09-25 07:06:21 字数 317 浏览 1 评论 0原文

这可能是一个完全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 技术交流群。

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

发布评论

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

评论(1

飘逸的'云 2024-10-02 07:06:21

WPF 使用 Dispatcher 线程来同步 UI 访问,因此本质上它们都将在同一线程上运行。您仍然可以以通常的方式实现异步调用,但是要更新 UI,您需要使用 Dispatcher 重新加入 Dispatcher 线程:

if (!Dispatcher.CheckAccess())
   Dispatcher.Invoke(new Action(() => item.Items.Add(subitem)));
else
   item.Items.Add(subitem);

您也可以在使用 EventAggregator 订阅事件时执行此操作,如下所示:

 eventAggregator.GetEvent<AnEvent>().Subscribe(DoWork, ThreadOption.UIThread);

这里有一些关于主题:

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:

if (!Dispatcher.CheckAccess())
   Dispatcher.Invoke(new Action(() => item.Items.Add(subitem)));
else
   item.Items.Add(subitem);

You can also do this when using the EventAggregator to subscribe to events as follows:

 eventAggregator.GetEvent<AnEvent>().Subscribe(DoWork, ThreadOption.UIThread);

There's some more info here on the subject:

http://msdn.microsoft.com/en-us/library/ms741870.aspx#threading_overview

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