棱镜CompositePresentationEvent发射两次

时间:2012-02-14 12:01:35

标签: c# wpf prism

在我的基础设施中,我发布了一个活动

  this.eventAggregator.GetEvent<ReportAddedEvent>().Publish(report);

报告是一个对象

在我的控制器中,我订阅了这个活动

  this.eventAggregator.GetEvent<ReportAddedEvent>().Subscribe(this.OnReportAdded);

我的问题是事件发生了两次。事件发布的整个代码中没有其他地方,因此我确定事件不会在其他地方被触发,我可以看到它只触发一次。

任何人都有建议或解决问题或知道问题所在。

1 个答案:

答案 0 :(得分:5)

我认为问题在于代码

this.eventAggregator.GetEvent<ReportAddedEvent>().Subscribe(this.OnReportAdded);

订阅ReportAddedEvent执行两次。

如果执行多次,则应检查(通过使用调试器和线路上的断点)。