【发布时间】:2015-09-28 09:42:59
【问题描述】:
我有与这篇帖子类似的问题Prism CompositePresentationEvent fires twice
我的问题是Publish 只触发了一次,但Subscribe 中的代码执行了两次。
这是我的发布代码。
EventAggregator.GetEvent<PubSubEvent<HardwareLoaded>>().Publish(new HardwareLoaded() { HardwareOK = _HardwareOK });
还有订阅代码。
IEventAggregator.GetEvent<PubSubEvent<HardwareLoaded>>().Subscribe(x =>
{
if (!x.HardwareOK)
{
MessageBox.Show("There was an issue loading hardware. See Log");
}
LoadingVisibility = Visibility.Collapsed;
});
我在Publish 和Subscribe 都放了一个断点,可以看到发布只触发一次,但订阅代码触发两次。这由显示两次的消息框支持。
我已经搜索了任何其他发布代码,但没有找到。
有什么想法吗?
【问题讨论】:
-
传递给
Subscribe的 lambda 被调用了一次,这我们知道,但可能对Subscribe的调用已经被调用了两次? -
您在哪里声明了订阅代码?会不会是你的代码调用了两次?
-
@Bijington 啊,这很重要,所以它实际上订阅了两次。我会检查一下。