复合 WPF EventAggregator 订阅丢失
在我的复合 WPF 应用程序中,当用户双击控件时会发布一个事件。 模块订阅事件并在必要时执行操作。
该事件似乎随机停止工作。 有时,当我运行应用程序时,我可以毫无问题地触发事件,而其他时候,我只能在模块停止接收事件之前触发几次。
当我查看调试器时,CAL EventAggregator
仍然有该事件,但该事件没有订阅。 EventAggregator
怎么会失去订阅?
In my Composite WPF application I have an event that is published when the user double-clicks on a control. Modules subscribe to the event and perform an action when necessary.
This event seems to stop working at random. Sometimes when I run the application I can trigger the event with no problems, other times I can only trigger it a few times before the modules stop receiving the event.
When I look in the debugger the CAL EventAggregator
still has the event, but the event has no subscriptions. How can EventAggregator
be losing subscriptions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原来是垃圾收集器删除了订阅。 我必须阅读内部结构,但是当我替换
它
时它开始工作。 UI 线程参数不是我的问题,但对于其他人来说,确保您也在正确的线程上处理事件可能很重要。
Turns out it was the garbage collector removing the subscriptions. I'll have to read up on the internals, but when I replaced
with
it started working. The UI thread parameters wasn't my problem, but for others it may be important to ensure you're handling the event on the right thread too.